Forums

Model Migration Error

Hi Guys, Can you please help i've just tried to run a pull request from bitbucket, there was changes that needed to be stashed which i did then ran a pull request again.

After it had done it's thing i then received this error:

"CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0002_auto_20180617_0045, 0003_auto_20180709_1952 in dsblog).
To fix them run 'python manage.py makemigrations --merge'
(myvenv) 06:08 ~/dsblog/blogbase (master)$ python3 manage.py makemigrations --merge"

Which i ran the merge which created the 004 migration file.

Then when i went to run makemigrations and migrate again it gave me this error:

"Applying dsblog.0002_auto_20180709_1914...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/db/migrations/migration.py", line 119, in apply
    operation.state_forwards(self.app_label, project_state)
  File "/home/mgcheetham/dsblog/blogbase/myvenv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 143, in state_forwards
    for name, instance in state.models[app_label, self.model_name_lower].fields:
KeyError: ('dsblog', 'comment'"

Which it's trying to apply the 002 migration which isn't correct, it needs to be 003.

However i now can't seem to either stop it from migrating the 002, or pull down and overwrite the 003 and make it apply it without getting the error.

Can you help as i can't find any help or troubleshooting information about migrations.

Is there a way i can stop it from looking at 002 or revert the changes?

Thanks

[edited by admin: formatting]

is this in production? if so- oh dear, sounds like you need to hire someone to read through your migrations/current db table configurations and sort it out.

if not- you know you could just delete all the migrations and database etc and start from an initial migration again right? :D