Skip to content
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

Error when reverting migrations #198

Open
4 of 5 tasks
leibowitz opened this issue Jun 20, 2018 · 0 comments
Open
4 of 5 tasks

Error when reverting migrations #198

leibowitz opened this issue Jun 20, 2018 · 0 comments

Comments

@leibowitz
Copy link

leibowitz commented Jun 20, 2018

Checklist

  • I have verified that I am using a GIS-enabled database, such as PostGIS or Spatialite.
  • I have verified that that issue exists against the master branch of django-cities.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

python manage.py migrate cities 0001_initial

Expected behavior

No errors

Actual behavior

psycopg2.IntegrityError: column "continent_code" contains null values

Full output (including Traceback):
https://gist.github.com/leibowitz/0427c3e70ffb07d81e1ecf82b349cf00

This is due to the last RemoveField of the 0002_continent_models_and_foreign_keys.py migration

As the documentation mentions:

The operation is reversible (apart from any data loss, which of course is irreversible) if the field is nullable or if it has a default value that can be used to populate the recreated column. If the field is not nullable and does not have a default value, the operation is irreversible.

Source: https://docs.djangoproject.com/en/2.0/ref/migration-operations/#removefield

Adding default='' to the Country.continent field definition

('continent', models.CharField(max_length=2)),
solves the issue.

I imagine retrospectively adding a migration between 0001 and 0002 (to add default='') would have prevented this issue, but it is a bit too late to do so.

The only way, in my opinion, is to add the default='' to the original definition - which shouldn't impact anyone already using django-cities.

#199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant