Get Django South working on Heroku with custom user models? - django

I'm trying to get South for Django to work on Hereoku. It didn't seem that hard, thanks to this example. However, I'm using a workaround for a bug in south that prevents initiating south when a custom user model is used in Django.
I use the following south commands local to initiate South (work around):
python manage.py syncdb
python manage.py convert_to_south myapp
python manage.py migrate myapp 0001 --fake
After that I pushed the code to Heroku and tried the following steps on Heroku:
python manage.py syncdb // this didn't sync the south apps
python manage.py convert_to_south myapp
// This gave the error saying that the apps were already added to south
My second try (after Heroku db reset and new push):
python manage.py syncdb // this didn't sync the south apps
python manage.py migrate
// Same south error as described in the south bug ticket
Is there anyone who can put me in the right direction?

I've searched for the answer in many places, but the only solution seems to generate the migrations files locally and push them to Heroku. That's something I wish I could prevent, but it is the only working option.
Hopefully, this will be solves as of Django 1.7, when migrations are built into Django. Until then, I moved away from Heroku.

Related

Django - Make migration command detects changes but on migrating says 'No migrations to apply'

i am new to django developement after making changes to my model i tried to run the command python manage.py makemigrations my_app
it detects changes in my model and shows me the message
todoapp/migrations/0001_initial.py
- Create model confess
- Create model UserChoice
- Create model comment
but on executing python manage.py migrate my_appcommand i've got this message
No migrations to apply.
i usually do this after making changes in models, i don't know what happened now.
plss help me.
Firstly, try
python manage.py makemigrations my_app
python manage.py migrate
If this does not work and the project is still in development:
Delete migrations folder and pycache folder.
Delete db.sqlite3 (your database).
Make and apply migrations again.
I think this will work.
Delete all migrations files and __pychache__except__init__.py from your project and app. Also db.sqlite3 database then rerun makemigrations and migrate commands. It should solve your issue.

Django 2.1 NOT NULL Constraint Failed When Creating Super User

I've been using Django for several months now without any issue but when I went to create a new project and add the super-user, I get the following error:
django.db.utils.IntegrityError: NOT NULL constraint failed: auth_user.last_login
All migrations have been created and applied successfully. I have destroyed and recreated the database a half dozen times to no avail. App migrations run without any problem whatsoever and this is the first time I've encountered this issue in an Django project.
I just realized this message was buried in the dozens of lines of error messages:
You have 12 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
Running just manage.py migrate and/or manage.py migrate appname did not apply the required system migrations. I had to do each one individually this time for some reason.
After running each one individually I was able to create a superuser without a problem:
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
I've never had to do that before, however. If anyone knows a reason as to why that happened I'd love to know but I've solved the main issue for now.
I'm too used
manage.py migrate admin
manage.py migrate auth
manage.py migrate contenttypes
manage.py migrate sessions
this helped for me
python manage.py createsuperuser

Can't add South to Django 1.6.2 Project

I've got an existing Django project that I'm trying to add South to. I'm fine with losing ally my data (in fact, I've already dropped/created the database several times).
The problem is that I do the following:
(in psql)
drop database myproject
create database myproject
(at the command line)
python manage.py syncdb --migrate
python manage.py schemamigration myproject.myapp --initial
python manage.py migrate myproject.myapp
Everything works great until I get to that last command; when I run it I get:
django.db.utils.ProgrammingError: relation "myapp_somemodel" already exists
(where "somemodel" is a model in myapp).
I've tried searching SO, but all the posts I found suggested the set of commands above. Can anyone please help me get South added to this project?
You need to run migrate with --fake option for your initial migration:
$ python manage.py migrate myproject.myapp 0001 --fake
Also see Converting An App chapter from South docs.

problems updating DB to heroku with south migrations

I have a Django proyect running in heroku for some time now, the thing is that, tree days ago, I've tryed to update my schema model but, every time I write
heroku run python manage.py migrate quizzer
heroku keeps telling me that everything's up to date, but I've changed my models.py folder and run schema migration as always.
If you know why this is happening or how can I force a schema migration to my heroku app please tell me how.
Ps: I cannot delete the hole database as the data stored in heroku and the data stored in my local server database are not the same, and I don't want to loose the data of my users
Here is a workflow for running a schemamigration on quizzer after modifying your models.py
./manage.py schemamigration quizzer --auto # create migration
./manage.py migrate quizzer # apply migration locally
git add .
git commit -m "Changed quizzer models, added schemamigration"
git push heroku
heroku run python manage.py migrate quizzer # apply migration on heroku
It sounds like you might have forgotten to check your migration file (usually found in appname/migrations) into git, commit it and push it to heroku.
I had this problem too. I solved this by running heroku restart and running the migrate command again. Don't know why it works (suspect it has to do with initial), but at least it works.
Hope that helps!
South might be missing from requirements.txt. Try:
pip freeze > requirements.txt
...followed by another git add/commit/push.
Also, according to the South installation instructions, syncdb must be run first, "to make the South migration-tracking tables". So try:
heroku run python manage.py syncdb
...then try the migrate command again.

Adding South to Django project, development & production

Adding South to an existing Django project. I have it installed on both the development machine and the "production" server.
I've done the following on the development machine, then: added South app to settings.py,
python manage.py syncdb
python manage.py convert_to_south myproject.myapp
then changed some models, then
python manage.py schemamigration myproject.myapp --auto
python manage.py migrate myproject.myapp
Seems to work so far. What I am now not so sure about is what to do on the production server. Just repeat all these steps manually? Upload modified settings.py, do syncdb, convert_to_south, upload modified models.py, do schemamigration, migrate? Something different? The tutorial here says something about adding migrations to the version control, so, presumably, they should be uploaded and somehow applied on the production server?
Furthermore, right now I am using sqlite3 on the development machine and mysql on the server - does it make things any different south-wise?
My guide says:
Install South on server. import south from shell just to make sure you are using the same python env.
Add 'south' to INSTALLED_APPS in settings.py.
Upload settings.py.
Restart server
python manage.py syncdb.
Upload new app/models.py and app/migrations/ dir.
Restart server.
python manage.py migrate app --fake 0001
python manage.py migrate app
To make sure the south migration table exists,
python manage.py syncdb
and then
python manage.py migrate myproject.myapp --fake 0001
python manage.py migrate myproject.myapp
That's what's worked for me. :)
No need to do this in Django >= 1.7
i am stuck on this more then 1 hour :)
and at last find 1.7 and more have in build upgrading-from-south
for more info https://docs.djangoproject.com/en/1.7/topics/migrations/#upgrading-from-south
may be this one help you