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'
Related
I'm a new django developer and I recently started a project, and am trying to get the database up and running.
For background: we are using a mysql database for storage, and the settings are configured for it. Using an Unbuntu DO server. I have also been using the virtual environment to run the commands below.
When we initially created the project we ran the makemigrations command, which populated the database with django tables, but not the Models, as we had not made any Models yet. I've now uploaded the Model code, however I could not make any new migrations, I got the error RuntimeError("Settings already configured").
According to this tutorial which I was following (https://www.geekinsta.com/how-to-customize-django-user-model/) some errors are normal and required me to delete and recreate the mysql database (which I did, it has the same name), and clear past migrations (the app/migrations/pycache is now empty). However I'm still experiencing the same error ("Settings already configured").
How can I fix this? I need to successfully run the makemigrations and migrate commands to populate the database. The new database and pycache are empty after I attempted the commands again. Thanks for any and all help.
I am trying to change some field names of Django models, but for some reasons Django does not want to see my migrations. I made sure the following things are properly set up:
myApp.apps.MyAppConfig is added to INSTALLED_APPS in settings.py
A migration folder with an empty __init__.py is present in my app folder
In myApp folder, I also have an empty __init__.py
The whole procedure works just fine locally with a SQLite database and I can change field names and run python manage.py makemigrations and python manage.py migrate to migrate the database. However in production where I use Docker Compose for orchestration and Postgres as database only the first migration works fine. Afterwards when I change any model field name and try to run docker-compose exec projectname django-admin makemigrations or docker-compose exec projectname python manage.py makemigrations or add the app name behind these commands nothing helps.
Then Postgres can't handle the request, because it doesn't know the new field name:
2022-03-11 14:40:22.136 UTC [81] ERROR: column model_name.new_field_name does not exist at character 357
What am I missing here? How can I get Django to migrate?
I had the same issues when using version control to submit changes to another environment.
What probably happens is that django believes it already made the migration, because of the information that is being passed along when you push those changes. What you need to do is to correct that behavior manually deleting those migrations or, if you don't need to keep information yet, force the migration from the beginning.
You may want to read the docs for future use, and I used the answers in this questions to solve the same issue.
At the end I was able to solve this issue by adding a Docker volume for the migrations folder. I believe a lot of times people put their entire code in a persistent volume, which would've also prevented this issue. However at least everything that needs to be persistent (obviously) needs a persistent volume.
I am working on a Django project with another developer. I had initially created a model which I had migrated and was synced correctly with a MySQL database.
The other developer had later pulled the code I had written so far from the repository and added some additional fields to my model.
When I pulled through his changes to my local machine the model had his changes, and additionly a second migration file had been pulled.
So I then executed the migration commands:
python manage.py makemigrations myapp, then python manage.py migrate in order to update my database schema. The response was that no changes had been made.
I tried removing the migration folder in my app and running the commands again. A new migrations folder had been generated and again my database schema had not been updated.
Is there something I am missing here? I thought that any changes to model can simply be migrated to alter the database schema.
Any help would be greatly appreciated. (Using Django version 1.9).
After you pull, do not delete the migrations file or folder. Simply just do python manage.py migrate. Even after this there is no change in database schema then open the migrations file which came through the git pull and remove the migration code of the model whose table is not being created in the database. Then do makemigrations and migrate. I had this same problem. This worked for me.
In your ProcFile add this line at the beginning.
release: python manage.py migrate
I'm in the process of preparing a Django application for its initial production release, and I have deployed development instances of it in a few different environments. One thing that I can't quite get happening as smoothly as I'd like is the initial database migration. Given a fresh installation of Django, a deployment of my application from version control, and a clean database, manage.py migrate will handle the initial creation of all tables (both Django's and my models'). That's great, but it doesn't actually create the initial migration files for my apps. This leads to a problem down the road when I need to deploy code changes that require a new database migration, because there's no basis for Django to compute the deltas.
I've tried running manage.py makemigrations as the first step in the deployment, in the hopes that it would create the migration files, but it reports that there are no changes to migrate. The only way I've found to get the baseline state that I need is to run manage.py makemigrations [appname] for each of my apps. Shouldn't makemigrations, called without a specific app name, pick up all the installed apps and create their migrations? Where am I going wrong?
You're going wrong at the very end -- yes, you do need to call manage.py makemigrations <appname> for each of your apps once. It's not automatically done for all apps.
Presumably that is because Django has no way of knowing if that is what you want to do (especially if some apps were downloaded from PyPI, etc). And a single command per app can't really be an extreme amount of work, right?
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'