migrations
migrations copied to clipboard
General error: 1832 Cannot change column 'example' used in a foreign key constraint
Hi everyone,
- CakePHP Version: latest as of now
- Migrations plugin version: latest as of now
- Database server (MySQL, SQLite, Postgres): 10.3.27-MariaDB-0+deb10u1
- PHP Version: PHP 7.3.19-1~deb10u1 (cli) (built: Jul 5 2020 06:46:45) ( NTS )
- Platform / OS: Debian 10
What you did
- create a migration via
bin/cake bake migration_diff MigrationName - realise I forgot to include something,
bin/cake migrations rollback
Actual Behavior
Exception: SQLSTATE[HY000]: General error: 1832 Cannot change column 'equipment_manufacturer_id': used in a foreign key constraint 'fk_products'
In [/var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php, line 185]
2021-04-10 17:05:36 Error: [PDOException] SQLSTATE[HY000]: General error: 1832 Cannot change column 'equipment_manufacturer_id': used in a foreign key constraint 'fk_products' in /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 185
Stack Trace:
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:185
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Util/AlterInstructions.php:112
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:619
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:1021
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/AdapterWrapper.php:514
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/TimedOutputAdapter.php:452
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/AdapterWrapper.php:514
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Plan/Plan.php:154
- /var/www/app/vendor/cakephp/cakephp/src/Collection/CollectionTrait.php:69
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Plan/Plan.php:155
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Table.php:722
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Db/Table.php:628
- /var/www/app/vendor/cakephp/migrations/src/Table.php:154
- /var/www/app/config/Migrations/20210410170322_MyMigratio.php:66
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Migration/Manager/Environment.php:112
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php:377
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Migration/Manager.php:523
- /var/www/app/vendor/robmorgan/phinx/src/Phinx/Console/Command/Rollback.php:124
- /var/www/app/vendor/cakephp/migrations/src/Command/Phinx/CommandTrait.php:37
- /var/www/app/vendor/cakephp/migrations/src/Command/Phinx/Rollback.php:81
- /var/www/app/vendor/symfony/console/Command/Command.php:256
- /var/www/app/vendor/symfony/console/Application.php:971
- /var/www/app/vendor/symfony/console/Application.php:290
- /var/www/app/vendor/symfony/console/Application.php:166
- /var/www/app/vendor/cakephp/migrations/src/Command/MigrationsCommand.php:126
- /var/www/app/vendor/cakephp/cakephp/src/Console/BaseCommand.php:179
- /var/www/app/vendor/cakephp/migrations/src/Command/MigrationsCommand.php:198
- /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php:336
- /var/www/app/vendor/cakephp/cakephp/src/Console/CommandRunner.php:172
- /var/www/app/bin/cake.php:12
This is limitation of database server. You cannot change column if it is used in a foreign key constraint.
You can drop foreign key, change column, then recreate foreign key.