Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General error: 1832 Cannot change column 'example' used in a foreign key constraint #486

Open
mehov opened this issue Apr 10, 2021 · 1 comment

Comments

@mehov
Copy link

mehov commented Apr 10, 2021

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
@garas
Copy link
Member

garas commented Apr 10, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants