53
You need to first create the migrations locally, add them to your repository, commit the files with the new migrations and then push to heroku.
The sequence is something like this:
1. (add/modify some someapp/models.py)
2. python manage.py makemigrations someapp
3. python manage.py migrate
4. git add someapp/migrations/*.py (to add the new migration file)
5. git commit -m "added migration for app someapp"
6. git push heroku
7. heroku run python manage.py migrate
10
1. Make migrations locally
$ python manage.py makemigrations && python manage.py migrate
2. Commit changes and push it on the server
$ git add --all
$ git commit -m "Fixed migrate error"
$ git push heroku master
3. Now run migrate on the server
$ heroku run python manage.py migrate
You also need to be sure that you haven’t ignored these migration paths
in your .gitingnore
file
- [Django]-How do I return JSON without using a template in Django?
- [Django]-Override django's model delete method for bulk deletion
- [Django]-How do I run Django and PHP together on one Apache server?
2
Answered for my case:
your_field=models.CharField(max_length=9,default=False)
Convert to
your_field=models.CharField(max_length=9,default='False')
My case:
In models.py for the field I wanted to set the default value to False
. First default = False
my contract without ''
. But after running python manage.py migrate, I got the above error. The problem was solved after placing False inside ''
.
Sometimes it is necessary for the default value in our field model to be a False string type.
If
default = False
If you write in the model, you will encounter this error.
In fact, depending on the type of field we have, we can not always set the default value of a field in the model to True
or False
. Must be converted to string for CharField
type.
- [Django]-Django query case-insensitive list match
- [Django]-What is a "slug" in Django?
- [Django]-Cleanest & Fastest server setup for Django
1
It sounds like you ran makemigrations
after you made changes to your model but before you had an initial migration file. Try to revert your app to the state it was before you added the new model and run makemigrations
again to create the initial migration. Then add your updates back in and run makemigrations
once more. This will create a second migration from your initial data structure to the new updated one. Then try your deployment.
https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps
- [Django]-Django startswith on fields
- [Django]-One app with many models vs. many apps with single model
- [Django]-Django+Postgres: "current transaction is aborted, commands ignored until end of transaction block"
0
It is a BAD IDEA to migrate to heroku the best practice is always to migrate locally, then push to heroku. But if you find yourself in this mess try reverting to the the initial migrations in heroku ‘NOT LOCALLY’ i.e run "heroku run manage.py 0001_initial "
it works for me atleast
- [Django]-Django Rest Framework with ChoiceField
- [Django]-Django test app error – Got an error creating the test database: permission denied to create database
- [Django]-Django: Want to display an empty field as blank rather displaying None