google_addressbook icon indicating copy to clipboard operation
google_addressbook copied to clipboard

Add "IF NOT EXISTS" syntax on create table

Open numericOverflow opened this issue 3 years ago • 1 comments

Avoids error if table already exists in DB

numericOverflow avatar Oct 28 '22 21:10 numericOverflow

Fixes this error I was getting when trying to upgrade existing installation of google_addresbook. Here's the error it was throwing and then immediately aborting install:

Do you want to activate the plugin google_addressbook? [Y|n] y
Creating package config file
Running database initialization script for google_addressbook
Creating database schema... ERROR: [1050] Table 'contacts_google' already exists
 (SQL Query: CREATE TABLE contacts_google (
 contact_id int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 changed datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
 del tinyint(1) NOT NULL DEFAULT '0',
 name varchar(128) NOT NULL DEFAULT '',
 email text NOT NULL,
 firstname varchar(128) NOT NULL DEFAULT '',
 surname varchar(128) NOT NULL DEFAULT '',
 vcard longtext NULL,
 words text NULL,
 user_id int(10) UNSIGNED NOT NULL,
 PRIMARY KEY(contact_id),
 CONSTRAINT user_id_fk_contacts_google FOREIGN KEY (user_id)
   REFERENCES users(user_id) ON DELETE CASCADE ON UPDATE CASCADE,
 INDEX user_contacts_google_index (user_id,del)
) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci
*/)
[FAILED]
ERROR: [1050] Table 'contacts_google' already exists

numericOverflow avatar Oct 28 '22 21:10 numericOverflow