yourlabs / django-cities-light

A simple app providing three models: Country, Region and City model. Also provided, a command to insert or update data from geonames database dumps. Status: stable.
http://django-cities-light.rtfd.org/
MIT License
332 stars 126 forks source link

The 0010_auto_20200508_1851 migration doesn't seem to be reversable #291

Open Lorac opened 1 week ago

Lorac commented 1 week ago

After I imported the data, I wanted to restart fresh, so I tried to migrate backward.

  Unapplying cities_light.0010_auto_20200508_1851...Traceback (most recent call last):
  File ".../lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: could not create unique index "cities_light_city_region_id_name_29b81cd4_uniq"
DETAIL:  Key (region_id, name)=(57, Neston) is duplicated.

Since I wanted to restart fresh, I deleted the offending cities. But I got more from the slug, too:

  Unapplying cities_light.0010_auto_20200508_1851...Traceback (most recent call last):
  File ".../.venv/lib/python3.11/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: could not create unique index "cities_light_city_region_id_slug_dc18c213_uniq"
DETAIL:  Key (region_id, slug)=(57, ashford) is duplicated.

Since there is duplication, It is impossible to revert to the old unique_together key which is : 'unique_together': set([('region', 'name'), ('region', 'slug')]),

image

marianoeramirez commented 1 week ago

Thats right. You should delete the duplicate row manually before revert.

Lorac commented 1 week ago

Would it be possible to squash all the migrations together?

marianoeramirez commented 1 week ago

It's not recommended because of this public library is being used across multiple servers in different situations. There are on other status and we want to allow them to move to a new version of the library without any issues.