-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
Merging tables so I can add PK to an existing table #691
Comments
According to #575 it seems that I'd have to implement it myself to contribute. |
Hello @brunomunizaf, I suggest you just apply the recipe you described (create a new table, dump the contents into it, drop old table and rename the new one), and that's it. Do not submit any pull request, unless you want to become much less ignorant in DB management :-) |
@groue my solution went pretty bad. I couldn't just select * from the old table and insert into the new one cause it said it had x columns and only provided x-1 values but I can't predict the autoincremented pk. So i decided to try another approach with the hidden rowid PK but for that I gotta ask you how to get this value since I don't have it set as a property from the PersistableRecord model. Could you give me a tip here? Thank you. |
I also wonder why executing "ALTER TABLE table ADD PRIMARY KEY id" doesn't work. 🤔 |
I guess this solves it: https://github.com/groue/GRDB.swift#advanced-database-schema-changes |
Hi,
I'm looking to add primary key to an existing table that doesn't have it and I haven't been able to just alter the current table with .autoIncrementedPrimaryKey so I figured out I'd have to create a temp copied table with .autoIncrementedPrimaryKey and then delete the old table and rename the copied table to the previous one's name - or I could just merge two tables but I couldn't find any merge reference on GRDB docs. Is there a merge functionality or I should do it through SQL statement?
PS: If there is an easier way to do this please let me know - i'm a complete ignorant in DB management.
Thank you,
Bruno.
The text was updated successfully, but these errors were encountered: