Drop index on groups failes when upgrading from part-db-0.6.0 to 1.0
Describe the bug
When running php bin/console doctrine:migrations:migrate to upgrade my part-db-0.6.0 to 1.0 I run into an issue when it tried to drop the index "name" on table "groups".
Additional Info: I use the docker-instance of partdb-symfony as given in the hint. The APP_ENV was set to prod (docker env as also the .env.local file) and .env.local was updated to point to a copy of my old databse.
To Reproduce
- Update .env.local to point to the partdb-0.6.0 database.
- run
php bin/console doctrine:migrations:migrate - See error
Expected behavior A clear and concise description of what you expected to happen.
Output Migration script
php bin/console doctrine:migrations:migrate
Application Migrations
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20200502161750 from 0
++ migrating 1 (Creates an inital empty database)
SS skipped (Reason: Old Part-DB Database detected! Continue with upgrade...)
++ migrating 20190902140506 (Upgrade database from old Part-DB 0.5 Version (dbVersion 26))
-> SET sql_mode = ''
-> RENAME TABLE `attachement_types` TO `attachment_types`;
-> RENAME TABLE `attachements` TO `attachments`;
-> CREATE TABLE currencies (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, iso_code VARCHAR(255) NOT NULL, exchange_rate NUMERIC(11, 5) DEFAULT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_37C44693727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
-> CREATE TABLE `measurement_units` (id INT AUTO_INCREMENT NOT NULL, parent_id INT DEFAULT NULL, unit VARCHAR(255) DEFAULT NULL, is_integer TINYINT(1) NOT NULL, use_si_prefix TINYINT(1) NOT NULL, comment LONGTEXT NOT NULL, not_selectable TINYINT(1) NOT NULL, name VARCHAR(255) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_F5AF83CF727ACA70 (parent_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
-> CREATE TABLE part_lots (id INT AUTO_INCREMENT NOT NULL, id_store_location INT DEFAULT NULL, id_part INT NOT NULL, description LONGTEXT NOT NULL, comment LONGTEXT NOT NULL, expiration_date DATETIME DEFAULT NULL, instock_unknown TINYINT(1) NOT NULL, amount DOUBLE PRECISION NOT NULL, needs_refill TINYINT(1) NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, INDEX IDX_EBC8F9435D8F4B37 (id_store_location), INDEX IDX_EBC8F943C22F6CC4 (id_part), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB
-> INSERT IGNORE INTO part_lots (id_part, id_store_location, amount, instock_unknown, last_modified, datetime_added) SELECT parts.id, parts.id_storelocation, parts.instock, 0, NOW(), NOW() FROM parts WHERE parts.instock >= 0
-> INSERT IGNORE INTO part_lots (id_part, id_store_location, amount, instock_unknown, last_modified, datetime_added) SELECT parts.id, parts.id_storelocation, 0, 1, NOW(), NOW() FROM parts WHERE parts.instock = -2
-> ALTER TABLE currencies ADD CONSTRAINT FK_37C44693727ACA70 FOREIGN KEY (parent_id) REFERENCES currencies (id)
-> ALTER TABLE `measurement_units` ADD CONSTRAINT FK_F5AF83CF727ACA70 FOREIGN KEY (parent_id) REFERENCES `measurement_units` (id)
-> ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F9435D8F4B37 FOREIGN KEY (id_store_location) REFERENCES `storelocations` (id)
-> ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F943C22F6CC4 FOREIGN KEY (id_part) REFERENCES `parts` (id) ON DELETE CASCADE
-> ALTER TABLE parts DROP INDEX parts_order_orderdetails_id_k, ADD UNIQUE INDEX UNIQ_6940A7FE81081E9B (order_orderdetails_id)
-> ALTER TABLE parts DROP FOREIGN KEY parts_id_storelocation_fk
-> DROP INDEX favorite ON parts
-> DROP INDEX parts_id_storelocation_k ON parts
-> ALTER TABLE parts DROP FOREIGN KEY parts_id_footprint_fk
-> ALTER TABLE parts DROP FOREIGN KEY parts_id_manufacturer_fk
-> ALTER TABLE parts CHANGE mininstock minamount DOUBLE PRECISION NOT NULL, ADD id_part_unit INT DEFAULT NULL, ADD manufacturer_product_number VARCHAR(255) NOT NULL, ADD manufacturing_status VARCHAR(255) DEFAULT NULL, ADD needs_review TINYINT(1) NOT NULL, ADD tags LONGTEXT NOT NULL, ADD mass DOUBLE PRECISION DEFAULT NULL, DROP instock, CHANGE id_category id_category INT NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE order_quantity order_quantity INT NOT NULL, CHANGE manual_order manual_order TINYINT(1) NOT NULL, CHANGE manufacturer_product_url manufacturer_product_url VARCHAR(255) NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE favorite favorite TINYINT(1) NOT NULL, DROP id_storelocation
-> ALTER TABLE parts ADD CONSTRAINT FK_6940A7FE5697F554 FOREIGN KEY (id_category) REFERENCES `categories` (id)
-> ALTER TABLE parts ADD CONSTRAINT FK_6940A7FEEBBCC786 FOREIGN KEY (id_master_picture_attachement) REFERENCES `attachments` (id)
-> ALTER TABLE parts ADD CONSTRAINT FK_6940A7FE2626CEF9 FOREIGN KEY (id_part_unit) REFERENCES `measurement_units` (id)
-> CREATE INDEX IDX_6940A7FEEBBCC786 ON parts (id_master_picture_attachement)
-> CREATE INDEX IDX_6940A7FE2626CEF9 ON parts (id_part_unit)
-> CREATE INDEX IDX_6940A7FE5697F554 ON parts (id_category)
-> DROP INDEX parts_id_category_k ON parts
-> DROP INDEX parts_id_footprint_k ON parts
-> CREATE INDEX IDX_6940A7FE7E371A10 ON parts (id_footprint)
-> DROP INDEX parts_id_manufacturer_k ON parts
-> CREATE INDEX IDX_6940A7FE1ECB93AE ON parts (id_manufacturer)
-> ALTER TABLE parts ADD CONSTRAINT parts_id_footprint_fk FOREIGN KEY (id_footprint) REFERENCES footprints (id)
-> ALTER TABLE parts ADD CONSTRAINT parts_id_manufacturer_fk FOREIGN KEY (id_manufacturer) REFERENCES manufacturers (id)
-> ALTER TABLE attachment_types DROP FOREIGN KEY attachement_types_parent_id_fk
-> ALTER TABLE attachment_types ADD filetype_filter LONGTEXT NOT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> DROP INDEX attachement_types_parent_id_k ON attachment_types
-> CREATE INDEX IDX_EFAED719727ACA70 ON attachment_types (parent_id)
-> ALTER TABLE attachment_types ADD CONSTRAINT attachement_types_parent_id_fk FOREIGN KEY (parent_id) REFERENCES attachment_types (id)
-> ALTER TABLE categories DROP FOREIGN KEY categories_parent_id_fk
-> ALTER TABLE categories ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE disable_footprints disable_footprints TINYINT(1) NOT NULL, CHANGE disable_manufacturers disable_manufacturers TINYINT(1) NOT NULL, CHANGE disable_autodatasheets disable_autodatasheets TINYINT(1) NOT NULL, CHANGE disable_properties disable_properties TINYINT(1) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> DROP INDEX categories_parent_id_k ON categories
-> CREATE INDEX IDX_3AF34668727ACA70 ON categories (parent_id)
-> ALTER TABLE categories ADD CONSTRAINT categories_parent_id_fk FOREIGN KEY (parent_id) REFERENCES categories (id)
-> ALTER TABLE devices DROP FOREIGN KEY devices_parent_id_fk
-> ALTER TABLE devices ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE order_quantity order_quantity INT NOT NULL, CHANGE order_only_missing_parts order_only_missing_parts TINYINT(1) NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE comment comment LONGTEXT NOT NULL
-> DROP INDEX devices_parent_id_k ON devices
-> CREATE INDEX IDX_11074E9A727ACA70 ON devices (parent_id)
-> ALTER TABLE devices ADD CONSTRAINT devices_parent_id_fk FOREIGN KEY (parent_id) REFERENCES devices (id)
-> ALTER TABLE footprints DROP FOREIGN KEY footprints_parent_id_fk
-> ALTER TABLE footprints ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> DROP INDEX footprints_parent_id_k ON footprints
-> CREATE INDEX IDX_A34D68A2727ACA70 ON footprints (parent_id)
-> ALTER TABLE footprints ADD CONSTRAINT footprints_parent_id_fk FOREIGN KEY (parent_id) REFERENCES footprints (id)
-> ALTER TABLE manufacturers DROP FOREIGN KEY manufacturers_parent_id_fk
-> ALTER TABLE manufacturers ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE address address VARCHAR(255) NOT NULL, CHANGE phone_number phone_number VARCHAR(255) NOT NULL, CHANGE fax_number fax_number VARCHAR(255) NOT NULL, CHANGE email_address email_address VARCHAR(255) NOT NULL, CHANGE website website VARCHAR(255) NOT NULL, CHANGE auto_product_url auto_product_url VARCHAR(255) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> DROP INDEX manufacturers_parent_id_k ON manufacturers
-> CREATE INDEX IDX_94565B12727ACA70 ON manufacturers (parent_id)
-> ALTER TABLE manufacturers ADD CONSTRAINT manufacturers_parent_id_fk FOREIGN KEY (parent_id) REFERENCES manufacturers (id)
-> ALTER TABLE storelocations DROP FOREIGN KEY storelocations_parent_id_fk
-> ALTER TABLE storelocations ADD storage_type_id INT DEFAULT NULL, ADD only_single_part TINYINT(1) NOT NULL, ADD limit_to_existing_parts TINYINT(1) NOT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE is_full is_full TINYINT(1) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> ALTER TABLE storelocations ADD CONSTRAINT FK_7517020B270BFF1 FOREIGN KEY (storage_type_id) REFERENCES `measurement_units` (id)
-> CREATE INDEX IDX_7517020B270BFF1 ON storelocations (storage_type_id)
-> DROP INDEX storelocations_parent_id_k ON storelocations
-> CREATE INDEX IDX_7517020727ACA70 ON storelocations (parent_id)
-> ALTER TABLE storelocations ADD CONSTRAINT storelocations_parent_id_fk FOREIGN KEY (parent_id) REFERENCES storelocations (id)
-> ALTER TABLE suppliers DROP FOREIGN KEY suppliers_parent_id_fk
-> ALTER TABLE suppliers ADD default_currency_id INT DEFAULT NULL, ADD shipping_costs NUMERIC(11, 5) DEFAULT NULL, ADD not_selectable TINYINT(1) NOT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE address address VARCHAR(255) NOT NULL, CHANGE phone_number phone_number VARCHAR(255) NOT NULL, CHANGE fax_number fax_number VARCHAR(255) NOT NULL, CHANGE email_address email_address VARCHAR(255) NOT NULL, CHANGE website website VARCHAR(255) NOT NULL, CHANGE auto_product_url auto_product_url VARCHAR(255) NOT NULL, CHANGE comment comment LONGTEXT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> ALTER TABLE suppliers ADD CONSTRAINT FK_AC28B95CECD792C0 FOREIGN KEY (default_currency_id) REFERENCES currencies (id)
-> CREATE INDEX IDX_AC28B95CECD792C0 ON suppliers (default_currency_id)
-> DROP INDEX suppliers_parent_id_k ON suppliers
-> CREATE INDEX IDX_AC28B95C727ACA70 ON suppliers (parent_id)
-> ALTER TABLE suppliers ADD CONSTRAINT suppliers_parent_id_fk FOREIGN KEY (parent_id) REFERENCES suppliers (id)
-> DROP INDEX attachements_class_name_k ON attachments
-> ALTER TABLE attachments DROP FOREIGN KEY attachements_type_id_fk
-> ALTER TABLE attachments ADD datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE type_id type_id INT DEFAULT NULL, CHANGE name name VARCHAR(255) NOT NULL, CHANGE filename filename VARCHAR(255) NOT NULL, CHANGE show_in_table show_in_table TINYINT(1) NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> ALTER TABLE attachments ADD CONSTRAINT FK_47C4FAD61F1F2A24 FOREIGN KEY (element_id) REFERENCES `parts` (id) ON DELETE CASCADE
-> DROP INDEX attachements_type_id_fk ON attachments
-> CREATE INDEX IDX_47C4FAD6C54C8C93 ON attachments (type_id)
-> CREATE INDEX IDX_47C4FAD61F1F2A24 ON attachments (element_id)
-> DROP INDEX attachements_element_id_k ON attachments
-> ALTER TABLE attachments ADD CONSTRAINT attachements_type_id_fk FOREIGN KEY (type_id) REFERENCES attachment_types (id)
-> ALTER TABLE users CHANGE name name VARCHAR(180) NOT NULL, CHANGE first_name first_name VARCHAR(255) DEFAULT NULL, CHANGE last_name last_name VARCHAR(255) DEFAULT NULL, CHANGE department department VARCHAR(255) DEFAULT NULL, CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE need_pw_change need_pw_change TINYINT(1) NOT NULL, CHANGE config_language config_language VARCHAR(255) DEFAULT NULL, CHANGE config_timezone config_timezone VARCHAR(255) DEFAULT NULL, CHANGE config_theme config_theme VARCHAR(255) DEFAULT NULL, CHANGE config_currency config_currency VARCHAR(255) NOT NULL, CHANGE perms_labels perms_labels INT NOT NULL, CHANGE last_modified last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL
-> ALTER TABLE users ADD CONSTRAINT FK_1483A5E9FE54D947 FOREIGN KEY (group_id) REFERENCES `groups` (id)
-> CREATE INDEX IDX_1483A5E9FE54D947 ON users (group_id)
-> DROP INDEX name ON users
-> CREATE UNIQUE INDEX UNIQ_1483A5E95E237E06 ON users (name)
-> DROP INDEX device_parts_combination_uk ON device_parts
-> ALTER TABLE device_parts CHANGE id_part id_part INT DEFAULT NULL, CHANGE id_device id_device INT DEFAULT NULL, CHANGE quantity quantity INT NOT NULL
-> ALTER TABLE device_parts ADD CONSTRAINT FK_AFC547992F180363 FOREIGN KEY (id_device) REFERENCES `devices` (id)
-> ALTER TABLE device_parts ADD CONSTRAINT FK_AFC54799C22F6CC4 FOREIGN KEY (id_part) REFERENCES `parts` (id)
-> CREATE INDEX IDX_AFC547992F180363 ON device_parts (id_device)
-> DROP INDEX device_parts_id_device_k ON device_parts
-> CREATE INDEX IDX_AFC54799C22F6CC4 ON device_parts (id_part)
-> DROP INDEX device_parts_id_part_k ON device_parts
-> ALTER TABLE orderdetails ADD last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE id_supplier id_supplier INT DEFAULT NULL, CHANGE supplierpartnr supplierpartnr VARCHAR(255) NOT NULL, CHANGE obsolete obsolete TINYINT(1) NOT NULL, CHANGE supplier_product_url supplier_product_url VARCHAR(255) NOT NULL
-> ALTER TABLE orderdetails ADD CONSTRAINT FK_489AFCDC4CE34BEC FOREIGN KEY (part_id) REFERENCES `parts` (id) ON DELETE CASCADE
-> ALTER TABLE orderdetails ADD CONSTRAINT FK_489AFCDCCBF180EB FOREIGN KEY (id_supplier) REFERENCES `suppliers` (id)
-> CREATE INDEX IDX_489AFCDC4CE34BEC ON orderdetails (part_id)
-> DROP INDEX orderdetails_part_id_k ON orderdetails
-> CREATE INDEX IDX_489AFCDCCBF180EB ON orderdetails (id_supplier)
-> DROP INDEX orderdetails_id_supplier_k ON orderdetails
-> DROP INDEX pricedetails_combination_uk ON pricedetails
-> ALTER TABLE pricedetails ADD id_currency INT DEFAULT NULL, ADD datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, CHANGE price price NUMERIC(11, 5) NOT NULL, CHANGE price_related_quantity price_related_quantity DOUBLE PRECISION NOT NULL, CHANGE min_discount_quantity min_discount_quantity DOUBLE PRECISION NOT NULL, CHANGE manual_input manual_input TINYINT(1) NOT NULL
-> ALTER TABLE pricedetails ADD CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES `orderdetails` (id) ON DELETE CASCADE
-> ALTER TABLE pricedetails ADD CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id)
-> CREATE INDEX IDX_C68C4459398D64AA ON pricedetails (id_currency)
-> CREATE INDEX IDX_C68C44594A01DDC7 ON pricedetails (orderdetails_id)
-> DROP INDEX pricedetails_orderdetails_id_k ON pricedetails
-> DROP INDEX name ON groups
Migration 20190902140506 failed during Execution. Error An exception occurred while executing 'DROP INDEX name ON groups':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups' at line 1
22:13:51 ERROR [console] Error thrown while running command "doctrine:migrations:migrate". Message: "An exception occurred while executing 'DROP INDEX name ON groups':\n\nSQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups' at line 1" ["exception" => Doctrine\DBAL\Exception\SyntaxErrorException^ { …},"command" => "doctrine:migrations:migrate","message" => """ An exception occurred while executing 'DROP INDEX name ON groups':\n \n SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups' at line 1 """]
In AbstractMySQLDriver.php line 79:
An exception occurred while executing 'DROP INDEX name ON groups':
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea
r 'groups' at line 1
In PDOConnection.php line 83:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea
r 'groups' at line 1
In PDOConnection.php line 78:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea
r 'groups' at line 1
Server Side
- Part-DB Version: Docker Instance, jbtronics/part-db1:latest@sha256:b82b22ab631c005bc67f73fa3085dfb7040f03e95f97c3197340d8471dec59fd
- PHP Version: as provided by the dockerfile
- Database Server: MySQL 8.0.20 (as Docker)
Desktop (please complete the following information): N/A
Smartphone (please complete the following information): N/A
Additional context
I already tried to drop the index manually and get the following message back Error 1067: Invalid default value for 'last_modified' SQL Statement: ALTER TABLE partdb.groups CHANGE COLUMNlast_modified last_modifiedTIMESTAMP NOT NULL DEFAULT '00-00-0000 00:00:00'
I also tried to allow 'last_modified' to be NULL and set the default value to NULL without success. That way i can manually drop the index, while the migration script still fails.
I think this could be related to your MariaDB version.
Requirements: A MySQL (at least 5.6.5) /MariaDB (at least 10.0.1) database server if you do not want to use SQLite.
and
https://github.com/Part-DB/Part-DB-symfony/issues/8
Sorry guys. I gave you wrong info. It's mysql not mariadb. I'm going to use mariadb now and retest the migration.
Using mariadb fixed the issue.
Part-DB should work on MySQL too, so i reopen the issue...