Troubleshooting
A migration failed
It ran in a transaction, so none of it stuck, and later migrations didn't run. Fix the file and run up again. Fill a new column from existing data shows this case and its fix.
Error: ant: migration 0016_add_handle failed and was rolled back: ERROR: could not create unique index "people_handle_key" (SQLSTATE 23505)
Key (handle)=() is duplicated.
A no-transaction migration failed partway
Some of it may have run, so up refuses to continue. Check the database, then pick one.
- If you undid what ran, or the file can run again: fix the file, run
repair, thenup. - If you finished it by hand: run
repair, thenbaseline <version>.
applied migration was changed
A file that has already run was edited. Put it back and make the change in a new migration. If the edit changes nothing, such as a comment, run repair. Line endings don't count as an edit.
Error: ant: applied migration was changed: 0015_orders. Applied migrations must not change: put the file back, write a new migration, or run repair if the edit changes nothing
status shows the file as changed. After repair, it is applied again.
applied migration is missing
A file that ran is gone. Put it back. For a Go migration, make sure the program imports the package that registers it. If the file is gone on purpose, repair forgets it.
drift reports something you did on purpose
To keep it, add it to the models and run snapshot, or put it in Config.Ignore. Each line says what the database would need to do to match: drop index people_nick_idx means the database has an index the snapshot doesn't.
The database differs from the snapshot. To match, it would need to:
drop index people_nick_idx on people
drop column people.nick
diff stops on a rename
A --rename whose new name isn't a table or column in the models, or that the snapshot already has, writes nothing. The message lists the names that are new in the models:
Error: ant: rename "users=peple": models have no table peple; new tables in the models: people
See renames.
diff refuses a name
PostgreSQL cuts a name over 63 bytes. diff says which one; give it a shorter name.
Error: ant: index name "tickets_a_very_long_index_name_that_goes_well_beyond_the_limit_of_sixty_three_bytes" is 83 bytes, and postgres keeps only 63: give it a shorter one
script refuses a no-transaction migration
script guards each migration with a check on the history table, which a migration without a transaction can't have. Use script --plain, or up. See deploying.
diff wrote something you do not want
Delete the file, and restore the snapshot.
git checkout migrations/versions/schema.snapshot.json