I get the following output when I run makemigrations and then migrate:
(roundwellenv) ruben#ruben-H81M-D2V:~/roundwell$ ./dev_migrations.sh
No changes detected in apps 'contenttypes', 'parents', 'admin', 'tips', 'tutors', 'login', 'auth', 'quiz', 'sessions'
Operations to perform:
Apply all migrations: admin, auth, contenttypes, login, parents, quiz, sessions, tips, tutors
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying login.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying parents.0001_initial... OK
Applying quiz.0001_initial... OK
Applying sessions.0001_initial... OK
Applying tips.0001_initial... OK
Applying tutors.0001_initial... OK
(roundwellenv) ruben#ruben-H81M-D2V:~/roundwell$ python manage.py createsuperuser
You have 21 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, login, parents, quiz, sessions, tips, tutors.
Run 'python manage.py migrate' to apply them.
I know something is really wrong because even if I delete pycache content and the conent from migration folders and a clean sqlite3 db it actually doesn't find any migrations it needs to apply unless I specify the apps I would like to create migrations for. Any clue as to what could be causing this? I suspect it might be my custom login app, but once the migrations are done (like they are on the system here the site is actually run) the DB works fine.
Try running the following, while in your project folder:
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
Then delete your sqlite DB, and try the migrations again.
Make sure you are in your project folder, or else this command will break your Django download!
Related
So I'm working on hosting a project and on my Heroku dashboard it says it's live, but every time I try to access it I get a 500 Server Error, even when trying to access it locally via Heroku CLI.
I tried running migrations because I get the following warning:
You have 21 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, recipe, sessions, users.
Run 'python manage.py migrate' to apply them.
Even after running makemigrations and migrate, as can be seen in screenshot below, any suggestions to what I might be missing?
C:\Users\davba\OneDrive\Documents\David\CSC-456\LIA_Project\Leftover-Ingredients->heroku run -a fathomless-cliffs-95117 python manage.py makemigrations
Running python manage.py makemigrations on ⬢ fathomless-cliffs-95117... up, run.3466 (Free)
No changes detected
C:\Users\davba\OneDrive\Documents\David\CSC-456\LIA_Project\Leftover-Ingredients->heroku run -a fathomless-cliffs-95117 python manage.py migrate
Running python manage.py migrate on ⬢ fathomless-cliffs-95117... up, run.3409 (Free)
Operations to perform:
Apply all migrations: admin, auth, contenttypes, recipe, sessions, users
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying auth.0009_alter_user_last_name_max_length... OK
Applying auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying recipe.0001_initial... OK
Applying sessions.0001_initial... OK
Applying users.0001_initial... OK
Applying users.0002_alter_profile_image... OK
C:\Users\davba\OneDrive\Documents\David\CSC-456\LIA_Project\Leftover-Ingredients->heroku run -a fathomless-cliffs-95117 python manage.py runserver
Running python manage.py runserver on ⬢ fathomless-cliffs-95117... up, run.6946 (Free)
Performing system checks...
System check identified no issues (0 silenced).
You have 21 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, recipe, sessions, users.
Run 'python manage.py migrate' to apply them.
November 17, 2021 - 00:20:55
Django version 3.2.8, using settings 'LeftoverIngredients.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
I am a beginner at the django and module and web applications.
Here is the traceback and the data:
OperationalError at /admin/learning_logs/example/
no such column: learning_logs_example.entry_id
Request Method: GET
Request URL: http://localhost:8000/admin/learning_logs/example/
Django Version: 1.11.7
Exception Type: OperationalError
Exception Value:
no such column: learning_logs_example.entry_id
Exception Location: C:\Users\Bryan\Desktop\LEARNI~1\ll_env\lib\site-
packages\django\db\backends\sqlite3\base.py in execute, line 328
Python Executable: C:\Users\Bryan\Desktop\LEARNI~1\ll_env\Scripts\python.exe
Python Version: 3.6.2
Python Path:
['C:\\Users\\Bryan\\Desktop\\learning log',
'C:\\Users\\Bryan\\Desktop\\LEARNI~1\\ll_env\\Scripts\\python36.zip',
'C:\\Users\\Bryan\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs',
'C:\\Users\\Bryan\\AppData\\Local\\Programs\\Python\\Python36-32\\lib',
'C:\\Users\\Bryan\\AppData\\Local\\Programs\\Python\\Python36-32',
'C:\\Users\\Bryan\\Desktop\\LEARNI~1\\ll_env',
'C:\\Users\\Bryan\\Desktop\\LEARNI~1\\ll_env\\lib\\site-packages']
Server time: Sat, 18 Nov 2017 18:36:14 +0000
For some reason, when I click that link that says "Examples" below,
it says this
I tried migrating but it says
(venv) C:\...\learning log>python manage.py makemigrations
No changes detected
(venv) C:\...\learning log>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
How did I get it to do that?
Well first I added the example entry/form with a TextField and then I added a "example". I added a ForeignKey object with the parameter as Entry.
I went back to edit my "example" but then the exception showed up.
EDIT:
Well janos wanted the output when I run python manage.py showmigrations learning_logs so here it is:
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 001_initial
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
learning_logs
[X] 0001_initial
sessions
[X] 0001_initial
Well I hope that helped.
I recreated the exception page right here
As the error message says,
the column entry_id in the table learning_logs_example does not exist.
This is not normal.
If schema migrations were created correctly and applied correctly,
then this should not happen.
Moreover, looking at this:
(venv) C:\...\learning log>python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
The Apply all migrations line should contain the name of your app.
The existing names are standard Django components.
The name of your app is probably learning_log or similar.
In short,
it seems that migrations don't exist for your app.
To debug this,
first of all check the output of showmigrations for your app:
./manage.py showmigrations learning_log
If you don't get an error, then please add the output to your question.
If you get an error CommandError: No migrations present for: ...,
then create the migrations:
./manage.py makemigrations learning_log
And then check the output of showmigrations again,
and please add the output to your question.
If the output looks something like this:
learning_log
[X] 0001_initial
...
That means the database has some records about applied migrations,
and in fact Django thinks that the migrations are correctly applied.
(When in fact they are not, based on your main error.)
With the information I have so far,
it seems your database got out of sync with the model:
some fields have been added to the model without applying to the database,
and the migrations were not correctly saved.
One simple solution could be to manually add the missing columns.
You can find the correct schema by looking at the migration file:
./manage.py sqlmigrate learning_log 0001
From this you should be able to find how the missing entry_id field is declared,
and then manually add it to the table with a query ALTER TABLE learning_logs_example ADD COLUMN entry_id ...,
where the rest of the parameters depend on the definition of the column in the output of sqlmigrate.
If the problem is only one or a few missing fields,
then this workaround may be enough to have something working.
(If not, then jump to the next section.)
You should not stop there though,
because the model may need some indexes as well.
You could either study further output of sqlmigrate and recreate all other objects that depend on learning_logs_example,
such as indexes, triggers.
But a cleaner solution will be to recreate all the tables of the app,
following these steps:
Dump the current data: ./manage.py dumpdata learning_log > learning_log.json
Drop all tables of the app
Recreate the tables of the app: ./manage.py migrate --fake learning_log zero; ./manage.py migrate learning_log
Restore the data: ./manage.py loaddata learning_log
If the workaround of adding columns manually doesn't work
(you stumble into more complicated problems),
then you have two choices:
If you cannot afford to lose data, well then you will have to track down and solve every single problem manually. After that's done, you should dump and restore the tables of the app as I explained in the previous section
If it's ok to lose data, then you can follow the procedure in the previous section, without the dumping and restoring steps. That is, drop and recreate the tables of the app
Finally,
to avoid further problems,
you need to make sure that all migrations are in sync with the model,
and are correctly added to version control.
A good way to test that is install the Django project in a different folder on your computer.
If that doesn't go smoothly,
then the setup is still not good.
Let me know if any of the above needs more clarification.
Is this the first time you are creating migrations for your application? If so, you need to specify the app name to make the migrations:
python manage.py makemigrations my-app
If data isn't matter, you can just drop your database file from here:
C:\Users\bryan_8nva8ki\Desktop\learning logs\db.sqlite3
(I saw that path from your logs)
Then you should make migrate again. Hope it will helps!
I have everything set up in my local environment and the code for my website up on the Heroku server, I'm just having serious trouble getting the schema to migrate to the PostgreSQL database on the Heroku server. Whenever I attempt heroku run python manage.py migrate I get the following (this would be an initial migration):
Running python manage.py migrate on baseballstatview... up, run.1653 (Free)
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, statview
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying sessions.0001_initial... OK
Applying statview.0001_initial... OK
Which seems fine but then using heroku pg:info it tells me I have 0 tables, and even further when I run heroku run python manage.py showmigrations this is what I get:
Running python manage.py showmigrations on baseballstatview... up, run.5059 (Free)
admin
[ ] 0001_initial
[ ] 0002_logentry_remove_auto_add
auth
[ ] 0001_initial
[ ] 0002_alter_permission_name_max_length
[ ] 0003_alter_user_email_max_length
[ ] 0004_alter_user_username_opts
[ ] 0005_alter_user_last_login_null
[ ] 0006_require_contenttypes_0002
[ ] 0007_alter_validators_add_error_messages
[ ] 0008_alter_user_username_max_length
contenttypes
[ ] 0001_initial
[ ] 0002_remove_content_type_name
sessions
[ ] 0001_initial
statview
[ ] 0001_initial
So it appears that the migrations are not going through and I'm wondering why that's the case. The database is empty, I've tried resetting it and trying again but nothing seems to work.
EDIT: below is the relevant settings.pyfor dj_database_url:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mlb_data',
'USER': 'postgres',
'PASSWORD': 'pw',
'HOST': 'localhost',
'PORT': '5432',
}
}
import dj_database_url
DATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
DEBUG = False
try:
from .local_settings import *
except ImportError:
pass
It looks from your code snippet that you are loading your dj_database_url configs BEFORE you attempt to bring in your local settings. This is the problem. What's happening here is that your local settings are overriding the production settings (with Postgres).
What's happening when you run the migration is:
Heroku is creating a new local SQLite database.
Doing the migrations.
Saying it's successful.
Exiting.
If you move that local settings stuff up above your db_database_url call, things should start magically working for ya!
I'm having a weird problem when migrating my project from django 1.7.4 to 1.8.5
In my project I extend the basic User model like so:
App users:
class User(AbstractUser):
age = models.IntegerField()
def __unicode__(self):
return self.username
Now when migrating in django 1.8.5 for some reasons I have to start by doing
python manage.py makemigrations
Which will make the migrations for the users app.
If I do
python manage.py migrate
directly after this it fails with this error
django.db.utils.ProgrammingError: relation "users_user" does not exist
Then I do:
python manage.py migrate users
Which fails
"Error creating new content types. Please make sure contenttypes "
RuntimeError: Error creating new content types. Please make sure
contenttypes is migrated before trying to migrate apps individually.
What is interesting is that even if this fails, now running
python manage.py migrate
Works
Operations to perform:
Synchronize unmigrated apps: messages, staticfiles, django_extensions, allauth, avatar, crispy_forms, debug_toolbar
Apply all migrations: sessions, users, contenttypes, admin, sites, account, auth, socialaccount
Synchronizing apps without migrations:
Creating tables...
Creating table avatar_avatar
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying account.0001_initial... OK
Applying account.0002_email_max_length... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
Applying sites.0001_initial... OK
Applying sites.0002_set_site_domain_and_name... OK
Applying sites.0003_auto_20151104_1309... OK
Applying socialaccount.0001_initial... OK
Has anyone experienced the same problems when migrating from an older django version to 1.8?
contenttypes is migrated before trying to migrate apps individually.
All you need to do is add the dependencies so your migrations will run in order.
Have a look at django.contrib.contenttypes.migrations, add the latest one as a dependency in account.migrations and it should all work fine.
I have Python Django project with app at apps/hello and a fixture with initial data at /apps/hello/fixtures/initial_data.json
When I git clone my Python Django project from github, checkout needed branch and run
./manage.py syncdb
it creates empty tables with no content i. e. does not load data from my initial_data fixture. Django asks me to register a superuser which is already registered in fixture.
Operations to perform:
Apply all migrations: admin, contenttypes, hello, auth, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying hello.0001_initial... OK
Applying hello.0002_auto_20141217_1326... OK
Applying hello.0003_auto_20141217_1329... OK
Applying sessions.0001_initial... OK
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): no
However I can steel load data manually
./manage.py loaddata apps/hello/fixtures/initial_data.json
Installed 12 object(s) from 1 fixture(s)
How to make Django do the same thing automatically on syncdb?
If you are using Django version 1.7 or later, you should probably know that automatic loading of fixtures has been deprecated:
If an application uses migrations, there is no automatic loading of fixtures. Since migrations will be required for applications in Django 2.0, this behavior is considered deprecated. If you want to load initial data for an app, consider doing it in a data migration.
If you're using the new built-in migrations, automatic loading of fixtures won't work.
I had the same problem, and I solved it by adding a few lines in my settings.py
FIXTURE_DIRS = (
os.path.join(BASE_DIR, 'hello/fixtures'),
)