Changing the id
field type , when I have not manually specified in the table, fails in migrations
#765
sumitsharansatsangi
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Yeah, it's tricky for Piccolo to change the primary key of a table, because it would also have to update any foreign keys pointing to the table. I agree we could do something better though. If the table has no data, one solution is to drop the table (just comment it out, and create a new migration). Then re-add it with the correct foreign key. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Earlier I have table as follows:
When I am changing it to following , migration is giving the error that id already exists.
The problem is piccolo is considering the
id
field as it is newly added.In the migration file , piccolo is generating the migration for
add_column
instead ofalter_column
One way to solve this problem is that if the table already exist and the column which is added is a primary key then it should generate the migration of alter_column, because piccolo auto generates only the id column as primary key , if it is not manually specified in the table.
Above suggested way will work in the following condition too( Where a different name is specified for the primary key), with a modification which is that
piccolo
has to generate migration forrename_column
too, ( for now without asking a questionDid you rename the column in the table ....
till piccolo doesn't support for complex primary key and specifying a complex primary key is not like as follows)
Before:
After:
Beta Was this translation helpful? Give feedback.
All reactions