You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I create tables with a table prefix and set a foreign key constraint. (See reproduce example). Now i change the table prefix and want to create the same tables in the same database with a different prefix.
The second call ends with: PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-[...]
I checked the generated queries in the mysql logfile and the error occurs on the last of this 6 queries.
createtable `foo_groups` (`id`bigint unsigned not null auto_increment primary key, `name`varchar(255) not null) default character set utf8mb4 collate utf8mb4_unicode_ci
createtable `foo_users` (`id`bigint unsigned not null auto_increment primary key, `group_id`bigint unsigned not null, `name`varchar(255) not null) default character set utf8mb4 collate utf8mb4_unicode_ci
altertable`foo_users` add constraint`users_group_id_foreign`foreign key (`group_id`) references`foo_groups` (`id`)
createtable `bar_groups` (`id`bigint unsigned not null auto_increment primary key, `name`varchar(255) not null) default character set utf8mb4 collate utf8mb4_unicode_ci
createtable `bar_users` (`id`bigint unsigned not null auto_increment primary key, `group_id`bigint unsigned not null, `name`varchar(255) not null) default character set utf8mb4 collate utf8mb4_unicode_ci
altertable`bar_users` add constraint`users_group_id_foreign`foreign key (`group_id`) references`bar_groups` (`id`)
The name of the constraint is the same as in the third query, so i get the error above. So perhaps the solution is to somehow add the table prefix to the constraint name, so this name becomes unique again.
Steps To Reproduce:
Minimal example with this 2 files. Just composer install and then php test.php.
Then change 'prefix' => 'foo_', to 'prefix' => 'bar_', and run again php test.php
Description:
I create tables with a table prefix and set a foreign key constraint. (See reproduce example). Now i change the table prefix and want to create the same tables in the same database with a different prefix.
The second call ends with:
PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table '#sql-[...]
I checked the generated queries in the mysql logfile and the error occurs on the last of this 6 queries.
The name of the constraint is the same as in the third query, so i get the error above. So perhaps the solution is to somehow add the table prefix to the constraint name, so this name becomes unique again.
Steps To Reproduce:
Minimal example with this 2 files. Just
composer install
and thenphp test.php
.Then change
'prefix' => 'foo_',
to'prefix' => 'bar_',
and run againphp test.php
composer.json:
test.php:
The text was updated successfully, but these errors were encountered: