0001_initial migrations Wont Create - django

So I'm new to django and recently tried to create some migrations for a project.
I created the project, created the application name, and set the application name in the Installed apps section in settings.
Whenever I run 'python manage.py makemigrations ' it gives me an output of:
'No changes detected in app'
Then when i run 'python manage.py migrate' it gives me:
Operations to perform:
Apply all migrations: (none)
Running migrations:
No migrations to apply.
There is a migrations folder within the application module, it just has an empty 'init.py' file inside.
Any suggestions?

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.

Your models have changes that are not yet reflected in a migration

In django1.9, tables have been in database already, i create init migration files
python manage.py makemigrations my_app
then, i run migrate:
python manage.py migrate my_app
It shows:
psycopg2.ProgrammingError: relation "p_record_segment" already exists
I want to fake it, first, i clean the django_migrations, then excute:
python manage.py migrate my_app --fake 0001_initial
It shows:
Running migrations:
Rendering model states... DONE
Applying my_app.0001_initial... FAKED
I think this will be fine, but when i run migrate again:
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.
I saw the history in django_migrations, and no changes in fact, but why django show me this.
Try using --fake-initial instead of just --fake

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