Replies: 3 comments 9 replies
-
The simplest answer is: they where coded like that. |
Beta Was this translation helpful? Give feedback.
0 replies
-
This could be considered a bug - and the code could be changed to resolve this. If anyone can be bothered. |
Beta Was this translation helpful? Give feedback.
4 replies
-
Just sent PR #51373 to fix this. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I had a strange issue today with my migration giving an error. I posted this query on stack overflow:
https://stackoverflow.com/questions/78274165/laravel-migration-failing-when-changing-primary-key-1068-multiple-primary-key-d
I have a table workflows with an auto-incrementing primary key called 'click_id'. I would like to add a field 'id' at the beginning of the table and make that the auto incrementing primary key.
This is the migration that fails:
The error is
SQLSTATE[42000]: Syntax error or access violation: 1068 Multiple primary key defined (Connection: mysql, SQL: alter table workflows add id bigint unsigned not null auto_increment primary key first)
This suggests that the
dropPrimary()
command is not completing before laravel continues onto the next line of the migration.The only workaround I've found to be sucessful is to split it into two separate chunks within the
up()
method.Another StackOverflow user Luca did some digging and found out that the
Blueprint
class does NOT follow the order of the instructions. The above 4 commands are translated into these SQL queries:The
drop primary key
is pushed later down the list causing the error.Can someone explain why it's done this way? Or any documentation as to when and how it decides what the order is to run them?
Beta Was this translation helpful? Give feedback.
All reactions