1

I worked with django 1.9 and added a new field (creation_date) to myapp/models.py. After that I run "python manage.py makemigrations". I got:

Please select a fix:

  1. Provide a one-off default now (will be set on all existing rows)
  2. Quit, and let me add a default in models.py."

I choose 1-st option and added value in wrong format '10.07.2016'. After this mistake I couldn't run "python manage.py migrate".

So I decided to change models.py and add a default value "datetime.now". But after that I still have problems with "python manage.py makemigrations". I see such things like that:

django.core.exceptions.ValidationError: [u"'10.07.2016' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]

How to solve this problem?

2
  • edit your question to show the most recently generated migration. This can problably be fixed by editing that manually. Commented Sep 17, 2016 at 12:21
  • You need to amend your data before the second migration's run. I guess you can do an objects.update(creation_date=timezone.now()) on them, but if it didn't work, you can manually do it through your database's shell. Commented Sep 17, 2016 at 12:24

1 Answer 1

1

As long as your migration isn't applied to the database you can manually update your migration file located in myapp/migrations/*.py. Find the string '10.07.2016' and update it to a supported format.

A less attractive solution would be to delete the old migration file (as long as it isn't apllied to the database) and create a new migrations file with python manage.py makemigrations. Because you've updated the model to use a default value it won't ask for a one-off default this time.

To check whether a migration is applied to the database run: python manage.py showmigrations.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.