Django migrations not applied - django

I am trying to do the portfolio project and when doing the migration part, I get this:
Operations to perform:
Apply all migrations: projects
Running migrations:
No migrations to apply.
What am I doing wrong? I am following the exact steps written on the document
I tried looking on google and could not find any good answers, please help.

try this:
python manage.py makemigrations <app name>
python manage.py migrate <app name>

Related

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

django-background-tasks migrations on heroku

I am trying to migrate dajngo-background-tasks on my app hosted in heroku. Migrations worked normally locally but when I tried to run:
heroku run python manage.py migrate
It returned 'No migrations to apply'
I've added 'background_task', to INSTALLED_APPS
I ran
heroku run python manage.py makemigrations background_task
And it created the required migrations
I even tried running
heroku run python manage.py migrate background_task
causing "CommandError: App 'background_task' does not have migrations."
PS: One thing I noticed is that when running migrate locally I get this text
Apply all migrations: admin, background_task, auth, contenttypes, sessions, <my_app>
But when I run it on the server I get
Apply all migrations: admin, auth, contenttypes, sessions, <my_app>
Every form of help will be very much appreciated!
You must not run makemigrations via heroku run. You must run it locally, commit the resulting migrations and push them to heroku, then run them there.
This is due to missing migrations in the django-background-tasks package. This issue has been fixed in the latest version. If you install 1.1.9 the deployment to heroku should work.

Django 1.9 with CORS dumping data: "corsheaders_corsmodel" does not exist

I'm developing a Django (1.9) Rest backend and AngularJS frontend with Cross-site referencing. While attempting to execute a ./manage.py dumpdata command, it throws the following exception:
$ python manage.py dumpdata -o dev/dumpdata.json
CommandError: Unable to serialize database: relation
"corsheaders_corsmodel" does not exist
LINE 1: SELECT COUNT(*) AS "__count" FROM "corsheaders_corsmodel"
Any idea how to handle?
I had this same problem, and resolved it by invoking python manage.py makemigrations specifically for the corsheaders app:
$ python manage.py makemigrations corsheaders
$ python manage.py migrate
I think what happened in my case was that, after an upgrade from Django 1.8 to 1.9, the initial migration was never applied when I updated my DB.
I tracked it down by noticing that the corsheaders app was not listed in the Apply all migrations output of python manage.py migrate:
$ python manage.py migrate
Operations to perform:
Apply all migrations: sessions, admin, xyz, auth, contenttypes
Running migrations:
No migrations to apply.
Yet running a manual migration for corsheaders actually creates the initial migration:
$ python manage.py makemigrations corsheaders
Migrations for 'corsheaders':
0001_initial.py:
- Create model CorsModel
After having done that, a migrate does show corsheaders in the output, and successfully applies the migration as expected:
$ python manage.py migrate
Operations to perform:
Apply all migrations: corsheaders, sessions, admin, xyz, auth, contenttypes
Running migrations:
Rendering model states... DONE
Applying corsheaders.0001_initial... OK
If corsheaders_corsmodel table does not exist, then there's no data to dump.
So you can just run:
$python manage.py dumpdata --exclude=corsheaders
I had the same problem and I solve it this way.

Migrations failing on Heroku

I have a Django-CMS project running on a Cedar stack using Django 1.7.1 and Python 3 at Heroku.
I can create a migration just fine using: heroku run python manage.py makemigrations which returns:
Migrations for 'zinnia':
0002_entry_content_placeholder.py:
- Add field content_placeholder to entry
However, running the migration via: heroku run python manage.py migrate returns:
Operations to perform:
Synchronize unmigrated apps: mptt, tagging, djangocms_admin_style, localflavor, django_comments, robots, ckeditor, sekizai, compressor, cmsplugin_plaintext, storages
Apply all migrations: admin, cms, zinnia, sessions, contenttypes, sites, auth, djangocms_link, djangocms_file, djangocms_picture, djangocms_text_ckeditor, menus
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
No migrations to apply.
Your models have changes that are not yet reflected in a migration,
and so won't be applied.
Run 'manage.py makemigrations' to make new migrations, and then re-run
'manage.py migrate' to apply them.
Re-running makemigrations and migrate simply returns the same error statement. What am I doing wrong?
im not so sure on that one, but after you ran the Migration, the file created:
0002_entry_content_placeholder.py
is as you notice, the second migration file.
If its an option for you, you could try to delete/rename the migration folder/files and run makemigrations again.
I got kinda the same error some time ago, and if i remember right, that did the trick.
Sorry for bad english

How to do a syncdb with django, when migrations are also involved

when I do a syncdb I get the following error everytime:
Not synced (use migrations):
- deals
- analytics
(use ./manage.py migrate to migrate these)
And when I run sudo python manage.py migrate. I get the following
Running migrations for deals:
- Nothing to migrate.
- Loading initial data for deals.
No fixtures found.
Running migrations for analytics:
- Nothing to migrate.
- Loading initial data for analytics.
No fixtures found.
I highly appreciate your help
From the output, it seems like the database is already synchronized with the migrations. There are no problematic errors. (Although you shouldn't really be root to run the migrations.)
If you're looking into creating more migrations, use the south documentation, which usually is just running the following after you modify the models:
python manage.py schemamigration --auto <APP>
And then use python manage.py migrate to apply the changes.
It looks like migrations have been already passed. Check south_migationhistory table in db.
If you want to sync new db for apps which has migrations just disable south in settings.py.
Have you ran a schemamigration initial yet?
./manage.py schemamigration deals --initial
./manage.py migrate deals
if you get the error, db already excists do this:
./manage.py schemamigration deals --initial
./manage.py migrate deals --fake