i have pushed my django application to heroku
and when i tried to fireup the url where my application is
i just got this error
ProgrammingError at /
relation "accounts_user" does not exist
LINE 1: ..."."is_active", "accounts_user"."date_joined" FROM "accounts_...
so i have figured out that the issue is with migration so i tried to run the makemigrations command in heroku
but unfortunately it returned as a failure with an error message
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration posts.0001_initial is applied before its dependency accounts.0001_initial on database 'default'.
so what i have tried is i have completely removed the migrations and database and runnned makemigration and migrate command in my local server and then i pushed it back to heroku but still its of no use
my local is running perfectly fine
i'm not sure where exactly the migrations issue is , in my heroku django application
i want to remove the previous migrations and have a clean database
but i have no idea on how to do that
I was facing the same issue yesterday. I was using Django rest and sqlite3 DB.
To solve that error I have clear all migration and delete a migration folder and clear DB file. After that, I have run migrations specific for that module and then run migrate command then it works fine for me. I hope it will work for you as well.
e.g.
$ python manage.py makemigrations module_name
$ python manage.py migrate module_name
Related
So I have deployed my Django project to Heroku, and now trying to migrate the database. I have everything working fine in my local sever. Then I tried to run the commands in heroku, as below.
python manage.py makemigrations
This worked fine.
Migrations for 'app_name':
contents\migrations\0001_initial.py
- Create model Book
- Create model Category
- Create model Content
Then of course, I tried : git add .git commit -m "migration" git push heroku master heroku run python manage.py migrate app_name
But then I got this error CommandError: App 'app_name' does not have migrations.
Strange thing is, after running python manage.py migrate, everything works fine in my local server. It's only the heroku server where the error occurs.
I've done some research for possible issues, none of which were relevant to mine.
For example I do have init.py in the migrations folder inside app_name directory. Also, I've tried heroku run python manage.py migrate as well as heroku run python manage.py migrate app_name but neither worked.
I'm very confused. What do you think is the problem? Thanks in advance. :)
So I have deployed my Django project to Heroku, and now trying to migrate the database. I have everything working fine in my local sever. Then I tried to run the commands in heroku, as below.
heroku run python manage.py makemigrations app_name'.
This worked fine.
Migrations for 'app_name':
contents\migrations\0001_initial.py
- Create model Book
- Create model Category
- Create model Content
Then of course, I tried : heroku run python manage.py migrate app_name.
But then I got this error CommandError: App 'app_name' does not have migrations.
I've done some research for possible issues, none of which were relevant to mine.
For example I do have __init__.py in the migrations folder inside app_name directory. Also, I've tried heroku run python manage.py migrate as well as heroku run python manage.py migrate app_name. I'm very confused. What do you think is the problem? Thanks in advance. :)
I had the same problem, I don't know why, but the following works for me (two commands in one line):
python manage.py makemigrations && python manage.py migrate app_name
As explained in heroku's help article Why are my file uploads missing/deleted?:
The Heroku filesystem is ephemeral - that means that any changes to
the filesystem whilst the dyno is running only last until that dyno is
shut down or restarted.
That is you do generate the migration files but they cease to exist shortly after when the app is reloaded.
In general the strategy you take is not a good approach to migrations as this can cause various issues, let's say you have multiple production servers each generates their own migrations this causes a conflict! In your situation suppose you do migrate this way and then later you want to add some new models this again will cause you problems.
One should always add their migrations to the version control (git, etc.) commit them and push them to production (here your heroku dyno). That is run python manage.py makemigrations locally, commit the generated migrations, push them and then run heroku run python manage.py migrate.
Currently I'm running into issues with my models.py and Postgresql. The site is deployed on Heroku using Postgresql and the problem is models.py. Currently, I have models.py as a models.Charfield() and it works fine with sqlite, but when I deployed it to production, Postgresql still reports that it's a models.IntFied(). And because it's an integer field it won't allow for characters for some reason.
Originally, I had it as a integerfield but decided to change to charfield, yet it still won't change to charfield.
Solutions I've tried: resetting the database on heroku, deleting and recreating the database on heroku.
Any help is appreciated,
Thanks
To sync your models to your database relational schema, you have to run the command:
python manage.py makemigrations
python manage.py migrate
I normally follow the steps in this order:
Ensure that your database changes have all been committed with git add and commit commands
Reset the heroku database, Run
{heroku pg:reset DATABASE_URL}
Push your current changes to heroku with
{git push heroku master}
Launch the heroku terminal
{heroku run bash}
On the heroku terminal run
{python manage.py migrate}
I created a django application so along the line I wanted to reset the entire database so I deleted the database and deleted all migration files. it is not the first time I have done such which I assume is not a bad way of doing it. so I ran the command like python manage.py makemigrations and I got this error in my terminal
django.db.migrations.exceptions.NodeNotFoundError:
Migration auth.0009_user_following dependencies reference nonexistent parent node (u'profiles', u'0001_initial')
I am totally confused and I dont have any idea on what to do next. HELP
You have a custom migrations in your generic app auth, just delete the file:
VIRTUALENV_PATH/lib/python2.7/site-packages/django/contrib/auth/migrations/auth.0009_user_following
You need to run this to get the initial migration:
python manage.py makemigrations <nameofyourapp>
Then run
python manage.py migrate
So, locally I've changed my models a few times and used South to get everything working. I have a postgres database to power my live site, and one model keeps triggering a column mainsite_message.spam does not exist error. But when I run heroku run python manage.py migrate mainsite from the terminal, I get Nothing to migrate. All my migrations have been pushed.
Get the list of migrations available for your apps (it will mark what are pending and what others are migrated).
heroku run python manage.py migrate <your app name> --list
if you have migrated with --fake, then identify the number of migration is pending (0003, for example) then do a revert of migrations to get the the previous state:
heroku run python manage.py migrate <your_app_name> 0002 --fake
now try again to migrate.
heroku run python manage.py migrate <your app name>
Did you run schemamigration before? If yes, go to your database and take a look at your table "south_migrationhistory" there you can see what happened.
If you already did the steps above you should try to open your migration file and take a look as well, there you can find if the creation column is specified or not!
I presume that you have created a migration to add mainsite_message.spam to the schema. Have you made sure that this migration is in your git repository?
If you type git status you should see untracked files. If the migration is untracked you need to git add path_to_migration and then push it to Heroku before you can run it there.