I've been finishing up my first Django app and have run into a snag with migrations in Heroku. I migrated with South locally and then attempted to move those migrations to the database on Heroku.
When I ran:
heroku run stentorian/manage.py syncdb migrate report
I received the following error:
['/app/stentorian', '/app/.heroku/venv/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/app', '/app/.heroku/venv/lib/python27.zip', '/app/.heroku/venv/lib/python2.7', '/app/.heroku/venv/lib/python2.7/plat-linux2', '/app/.heroku/venv/lib/python2.7/lib-tk', '/app/.heroku/venv/lib/python2.7/lib-old', '/app/.heroku/venv/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/app/.heroku/venv/lib/python2.7/site-packages', '/app/.heroku/venv/lib/python2.7/site-packages/PIL']
Error: Command doesn't accept any arguments
I've researched this and can't seem to find how to resolve this. Prior to this, I installed the django-flaggit app to my application, which doesn't use migrations, and had to use a traditional syncdb to get the tables set up in Heroku. I'm wondering if this had an affect.
If anyone has any insight into this issue, it would be much appreciated.
What you are doing here is actully calling two different commands in a row: syncdb and migrate.
The usual workflow with south is to run syncdb to sync all your non-south-supported apps, and then migrate, to work on south-supported apps. Actually, if you just run syncdb with south installed, it will tell you which apps are unsynced and must be migrated.
So, to summarize:
heroku run stentorian/manage.py syncdb
heroku run stentorian/manage.py migrate report
Related
I'm trying to implement Google Login on my Django production website. It works fine on development server, but on my production server, I face this issue after having run python manage.py migrate. I'm not sure what to do, I already tried deleting all the migrations and re-running makemigrations and migrate.
Checklist
run showmigrations to see which migrations are done.
if the relevant migration containing the table appears to be migrated, rollback and run migrate again.
when you want to regenerate migration files, you need to first rollback while you have the old migration files.
if you'd like to check which tables exist, use dbshell or other shell depending on the database you're using.
Other things
I would not recommend regenerating migration files just because there is some db issue.
I've been stuck on an issue for a while where I have a model that I've created locally (class User(AbstractUser)), ran "python manage.py makemigrations" and "python manage.py migrate", which works and interacts correctly with the django server when run locally.
When I push this to heroku however, I receive an error response to certain api requests which essentially say "relation "app_user" does not exist". I assumed this was because somehow the postgreSQL db didn't receive the migrations when the app was deployed to heroku. After logging into the db I noticed that it had a few other tables, including "auth_user" (I assume this is a default django table), but not "app_user". I have done "heroku run bash" and "python manage.py migrate" in an attempt to migrate the changes to the postgreSQL db, but this doesn't have any effect.
I'm not sure if this will be useful but the postgreSQL server I'm using is the standard Heroku Postgres Hobby Dev add-on.
My questions are:
Should running "python manage.py migrate" on heroku update the postgreSQL database? If so, how does this work?
Given that the migrations are all on heroku, how can I manually update the postgreSQL with the migrations?
Fixed by deleting old heroku db and creating a new one. Unsure what exactly caused the issue above but I feel it may be because we deleted all migrations on the repo at some point in the past (to start from scratch), which meant the current db state was not applicable to migrations in the repo and so could not be applied. After doing this, running migrate on the remote server works perfectly.
Added a small model 'new_model' in existing app 'existing_app' on Django,
Entered commands manage.py makemigrations and manage.py migrate. It migrated perfectly the changes to local database.
Tried to apply same on heroku but its not working there. I then tried to setup heroku database in local settings.py of project and migrations worked, but it shown some well known error. I have attached the output with this discusssion. Attaching the final screenshot the final screenshot as output.
Just In Case if it may help_________
The following are the methods I have applied before the final solution:-
With heroku run manage.py makemigrations
Adding makemigrations command to procfile
Pushing migrations as well, so it may replace server migrations
Heroku bash and tried "makemigration" and "migrate" on it
Alternate solution result Alternate solution result
The all four mentioned steps provided this output:- "No migrations to apply, and on migrate it shows you dont have new migrations",
helping out to migrate changes on database.
Thank You.
I made some changes to the db (i.e. added on column). I can make and run migrations just fine in my local env, the problem is in Production. I have made the migrations and pushed them to my remote repo, but when I run the migrations in production, nothing happens. I can makemigrations in production but when I run "heroku run python manage.py migrate", the system says, that are no migrations to implement.
This is worth mentioning though, initially I ran "heroku run python manage.py migrate --fake" because I had a lot intermediary tables that threw the error "table xxxxxx already exist" everytime I tried to run a migrations, so that fixed that problem but I believe that the actual change that I wanted(i.e. adding a column to the db) to make, actually got migrated as fake migration. How can I fix this?
I made many changes in my django app and when working locally i reset the database, deleted the migration and reseted south, recreated everything all over and it worked fine.
when trying to do the same in Heroku,
after droping the database using:
heroku pg:reset DATABASE
and also reseting south using:
heroku run ./manage.py reset south
and then pushing the Django app when looking at the heroku migration list using:
heroku run ./manage.py migrate --list
i can still see all of the old imgration,
though they are empty-- no * in the ()
so even after doing
heroku run python ./manage.py migrate accounts --fake
i still get migration errors:
DatabaseError at /admin/accounts/userprofile/
****relation "accounts_userprofile" does not exist
LINE 1: SELECT COUNT(*) FROM "accounts_userprofile"****
what can i do to solve it? is there a wayy to remove old migrations in heroku and just do it simple like when working locally by starting all over again?
or is their any other solution?
--fake is used when the database tables already exists and you no longer need to actually migrate the real database. As the tables don't exist, you should just run migrate without --fake.