Recently, I moved from Linux Mint to Ubuntu, uploaded my project's code to Github, downloaded it again and tried to continue developing. But I have a problem with South:
I tried migrating the apps(many apps) normally:
manage.py schemamigration apps --auto,
But I got:
"You cannot use --auto on an app with no migrations. Try --initial."
Then I tried '--initial',
But when I migrated the apps '$ ./manage.py migrate apps', I got:
"These migrations are in the database but not on the disk:
...(all the migrations I had, not sure how they ended up there)
I'm not trusting myself; either fix this yourself by fiddling
with the south_migrationhistory table, or pass --delete-ghost-migrations
to South to have it delete ALL of these records (this may not be good)."
I don't care about keeping the migrations so I tried python manage.py --delete-ghost-migrations, but I got "Unknown command".
Then I tried reseting migrations the way this post recommends, so I did:
$ python manage.py reset south
But I got "Unknown command" again.
¿How can I fix this so I can keep working on my project? Sorry if it is something obvious.
*When I was working on Linux Mint I used Mysql, now on Ubuntu I intalled Postgre. This probably doesn't have anything to do with the error cause I think I got it right and configured it correctly with my django project. But maybe you should know it if the solution needs some database manipulation. Thanks in advance.
Use the following command to clear the database:
./manage.py sqlclear south | ./manage.py dbshell
then make sure to remove the migrations directory in the app to fully reset south:
rm [app_name]/migrations
Related
I started creating my website on my own PC using the Django-cms install script then I tried to add a lot of applications such as Django-Helpdesk and others and everything was smooth until I tried to add pieces of djangoSHOP demo project and dependencies to email_auth.
Then I started to have report that the migration history was inconsistent and migrations applied out of order.
Before adding djangoShop to the installed apps, I just add the following commands to setup the DB:
manage.py migrate --run-syncdb --noinput
manage.py migrate --noinput
and everything was ok.
Now, as I'm just starting, I don't have changes to the schema to apply but most of the django apps I try to install have migrations folders with several migrations.
I don't want to update an existing schema, I want to create a new one.
I'm working from a blank database so do I really need to apply all those migrations ? To me it seems that the default behaviour of running migrations is not compatible with starting from a blank db,
I don't understand what to do just initialise the database to just have the required tables created.
Did anyone got the same kind of problems?
How did you fixed it?
Edit:
django-cms>=3.5,<3.6
Django 1.11.19
Error message:
Django InconsistentMigrationHistory: Migration Helpdesk.000xxxxx.py is applied before its dependency email_auth.0001_initial.py on database 'default'
I am new to publishing django apps on heroku.
I have read their tutorials and figured I would start simple by modifying their template django project.
So far everything was good.
Then I made an app as one does, made a model and ran
python3 manage.py makemigrations my_app
python3 manage.py migrate
and things seemed ok.
I then pushed to heroku and there were no immediate complaints.
However, now when I try to make save a new model I get the error:
ProgrammingError at /my_app/
relation "my_app_myappmodel" does not exist
LINE 1: INSERT INTO "my_app_myappmodel" ("field1", "field2", "field3") VALUES...
odd...
So I run this locally and everything works fine.
I have tried cleaning my migrations, faking my migrations, squashing my migrations, etc (as other S.O. posts suggest)
Nothing works.
What is up and how do I fix it?
You need to actually run the migrations on Heroku once you have pushed the code generated by makemigrations. You do this via heroku run manage.py migrate.
run the following command from your terminal
heroku run python manage.py migrate
or you can also do:
in your local settings.py, change your DATABASES variable to use the heroku one then run from the terminal
python manage.py makemigrations
python manage.py migrate
but you should not normally locally make changes to the heroku production database (as in option 2) except if you are really desperate or don't care
I am building an app called 'competencies'. I made changes to models, migrated the app locally, and everything worked. This is my eighth migration on the app.
I have deployed the app on heroku, so I committed changes and pushed to heroku. I can see that the changes went through, because the new migrations appear in the heroku files. When I log in to heroku and try to migrate the competencies app, I get the following error:
NoMigrations: Application '<module 'django.contrib.admin' from '/app/.heroku/python/lib/python2.7/site-packages/django/contrib/admin/__init__.py'>' has no migrations.
I have searched for this error, and I have not found anything meaningful. Can anyone suggest what I am doing wrong, or how to address the issue?
django.contrib.admin should not have migrations. Contrib packages are not south managed.
If you EVER ran python manage.py schemamigration django.contrib.auth --XXX on your local it would create the migrations folder in your local copy's install of the venv's django. However, this will never get transferred to heroku.
test something for me. create a new copy of your site on your local machine
new DB
new virtualenv
new folder w/ new clone of repo
try to run python manage.py migrate if you get the same error its b/c you broke your virtualenv with south.
Something else you could try IF your database models have not changed a bunch since the last working copy:
roll your models back to the last working configuration
delete EVERY app's migrations folder
truncate south_migrations table
run python manage.py schemamigration --initial X for each of your apps.
push and migrate --fake
redo your model changes
create migrations for the model changes
push and migrate regularly
I recently encountered this error after dumping a live database to a dev box for testing data migrations.
One of the dependencies was throwing this error (specifically taggit). I think that I have a different version of taggit on the dev box which does not have migrations, but the database I dumped had two migrations for taggit in south_migrationhistory.
I deleted the entries in south_migrationhistory for the problem app erroneously claiming NoMigrations and that solved my problem. Everything's running again.
Apart from many answers posted above, south.exceptions.NoMigrations is often exception after 2014 (Django 1.7) because of changed migrations directory. The directory is default for Django built in migrations.
For south migration, the directory is south_migrations. South>=1.0 can recognize this and automatically detect migrations. See details here on Django docs
In this case, update South:
pip install -U South
Or you can also specify migration directory on settings file (for every app installed).
I found an odd edge case, involving Kombu.
I'm maintaining a legacy Django 1.5 project on Ubuntu 14.04, and I previously had this setting to get Kombu to play nicely:
SOUTH_MIGRATION_MODULES = {
'kombu_transport_django': 'kombu.transport.django.south_migrations',
}
However, after I upgraded to Ubuntu 16, there were some minor tweaks in the Python stdlib that again broke Kombu. Upgrading Kombu was the only immediate solution, but that gave me another Kombu error similar to what OP found:
NoMigrations: Application '<module 'kombu.transport.django' from '/myproject/.env/local/lib/python2.7/site-packages/kombu/transport/django/__init__.pyc'>' has no migrations.
This error message is nearly worthless, but I eventually realized the problem was my SOUTH_MIGRATION_MODULES setting. It turns out, the old kombu.transport.django.south_migrations was removed, and South trying to import this missing migration directory is what was causing the error. The fix was to remove that line.
Try pip install --upgrade django
The NoMigrations error often shows up if you downgrade your Django version.
In my case, I had installed a package which automatically uninstalled my current Django version and installed a downgraded it.
Installing the updated version was a quick fix.
Also, you may want to check in your INSTALLED_APPS if you have included all of your apps including the 'django.contrib.auth' and 'django.contrib.admin'
I have successfully synced my database using south on the local server. I am having problems using south in Heroku. When I run
git add app/migrations/*
git commit -m 'adding new migrations'
heroku run python manage.py migrate app
I am getting a DatabaseError. Relation field already exists.
Any ideas why this isn't working? Also, do I need to run migrations locally and on the production environment each time one of my models change? Thanks for reading.
it seems you already have the fields in your database for that app. try faking the migrations by running
heroku run python manage.py migrate app --fake
do this on Heroku:
heroku run python manage.py migrate YOUR_APP_NAME 0001 --fake
then
heroku run python manage.py migrate YOUR_APP
that solved it for me. Just running migrate would give errors as for some reason south would try to run the initial migration as well. So I faked that one, and running the first actual migration (0002) worked fine after.
I am working on Python/Django and I am trying to use South to manage my database. In local environment is working great. The problem comes when I deploy to Heroku. The issue is that when I create a migration with
$heroku run manage.py schemamigration mydjangoapp
It looks like it works (the shell confirmed it), however, then I try to use migrations and it won't work. When I do:
$heroku run python manage.py migrate mydjangoapp
I get this;
The app 'createtuto' does not appear to use migrations
I checked on the problem and it looks like heroku doesn't allow South to create the migration directory at /myDjangoapp/migrations.
Is there anything I can do to make it work?
I tried to use convert_to_south, but I got the same results: At the beginning it looks like it worked, but It did not, not migration created.
When you run 'heroku run' it connects to an isolated instance of your deployed environment. It does create the migration, however that migration is not contained within your slug. Each time you do a 'git push heroku master' it installs your dependencies and packages your application into a slug. This is more or less a tarball of your application which enables Heroku to easily deploy it to new dynos as you scale up.
In order to run a migration on Heroku you would create the migration locally, check it in, then run the migration on heroku. Something similar to:
manage.py schemamigration mydjangoapp
git add mydjangoapp/migrations/*
git commit -m 'adding new migrations'
git push heroku master
heroku run python manage.py migrate mydjangoapp
I follow the direction from Mike Ball here successfully:
http://www.mikeball.us/blog/using-south-on-heroku/
Like CraigKerstiens answer said, you should make the migration locally first then push to heroku. Before you make a migration on Heroku, make sure you convert your Heroku instance into south, for example
heroku run bin/python django_project/manage.py convert_to_south django_app