Django migrations

any process to follow before running the git log --online command
Under reverting migrations part-I

1 Like

Not sure what the question is but to revert migrations, you need to do the following:

  1. Revert to the correct migration:
    python manage.py migrate your_app 0013

(assuming you app name is your_app and migration 0013-### is the one you need to go back to.)

  1. Revert you code back to the same state:
    This step assumes that you have been keeping your git repository up to date and that you have a commit corresponding to your target migration. If you have, you run git log --oneline to find the corresponding commit and then run git reset --hard commit_identifier.

This will return your code the the state at this commit and remove all code that was added subsequently relating to the incorrect migrations you want to roll back.

So to answer you question, re what to do before git log --oneline, you would have to have kept your repository in line with your migrations.

Hope this helps!

1 Like

I am following the ultimate django course and I was trying to create migrations but this error popped up in the terminal when I ran the command.

It is impossible to add a non-nullable field ‘collection’ to product without specifying a default. This is because the database needs something to populate existing rows.

Django already offers to apply a fix.

  1. Provide a one-off default now (will be set on all existing rows with a null value for this column)

OR

  1. Quit and manually define a default value in models.py.

I tried setting null to true but it didn’t work.