MySQL migrations: Multiple primary key defined when sql_generate_invisible_primary_key=ON #48522
Replies: 5 comments 6 replies
-
Hi there, Thanks for reporting the problem you are encountering, but it looks like this is a question which may be better suited for a support channel. We only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repository you can try one of the following channels: However, this issue will not be locked and everyone is still free to discuss solutions to your problem! Thanks. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Experiencing this as well, it is clearly a bug, laravel creates the table then alters it, so the effect of the auto gen primary kicks at creation point. |
Beta Was this translation helpful? Give feedback.
-
What a spectacular mistake by whoever thought that |
Beta Was this translation helpful? Give feedback.
-
Wow - what an issue (and I faced the same one, got resolved thanks to this discussion) |
Beta Was this translation helpful? Give feedback.
-
Laravel Version
10.19.0
PHP Version
8.2.8
Database Driver & Version
MySQL 8.0.31 (Azure Database for MySQL)
Description
Azure Database for MySQL has the 'sql_generate_invisible_primary_key' option set to ON by default.
This issue affects all MySQL >= 8.0.30 where sql_generate_invisible_primary_key is set to ON.
When migrating table with non-standard PK (standard in my case is unsigned numeric with auto_increment), unsigned bigint autoincrement invisible column named my_row_id is automatically generated and migration crashes when trying to create second primary key on column specified in migration itself.
Steps To Reproduce
creates following table
and then it tries to set 'id' as PK which causes
Syntax error or access violation: 1068 Multiple primary key defined SQL: alter table
cart_storage
add primary key (id
))Further Analysis
When I tried to create table directly by SQL:
It worked as expected, so after little bit of investigation i found that problem must be inside Blueprint::toSql() and MysqlGrammar::compilePrimary(), in case of enabled sql_generate_invisible_primary_key there must be different method to compile primary key than ALTER one.
Beta Was this translation helpful? Give feedback.
All reactions