Skip to content

Alter column to nullable #1969

Answered by simolus3
bernardoveras asked this question in Q&A
Discussion options

You must be logged in to vote

This is quite simple to do with drift's builtin support for complex table migrations. Essentially, you

  1. Change your table definition to make the column non-nullable.
  2. Re-run the build runner and increase your schemaVersion.
  3. Write a migration that calls await m.alterTable(TableMigration(yourModifiedTable));. This will re-create the table without loosing data. In your case, you don't need a more complex migration since all the existing data is compatible with the new schema (non-nullable rows can of course be stored in a nullable column).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bernardoveras
Comment options

Answer selected by bernardoveras
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants