django error OperationalError at /admin/blog/post/ - django

i get this error in simple django programme run..
OperationalError at /admin/blog/post/
no such table: blog_post

if django version >=django 1.7
python manage.py makemigrations
python manage.py migrate
else
python manage.py schemamigrations
python manage.py migrate
so you need to migrate (map the model changes / new models into database tables) the changes so that your page works properly

delete the migrations folder in app and then do :
python manage.py makemigrations
python manage.py migrate
python manage.py migrate --run-syncdb
it worked for me

You need to run migrations before you can do that operation. The necessary tables don't exist in your database (as described by the error).

Check for a typo in the name of your Model. If you change your model name after makemigration and migrate, then it doesn't work and find the correct model name anymore.

Related

Django.Programming Error: Table Name Does Not Exist - How to solve?

I deleted a model in Django which I created for testing purposed. Now when I try and run makemigrations and mirgrate I get the following error:
django.db.utils.ProgrammingError: table "members_test" does not exist
Is there a standard procedure I should be doing when deleting a model? I only deleteed the code out of my Models file and tried migrating after.
I've only tried runing migrate and make migrations in addtion to scouring the web.
Simply you can delete all migrations folder and re-migrate using below command:
python manage.py makemigrations appname
python manage.py sqlmigrate appname 0001
python manage.py migrate

django runserver : relation "django_migrations" already exists

I have a django project source code, which includes several apps. The source code have been run successfully on one environment, but when transplanted to another device, with the same postgresql version(9.4.4), python version(2.7.5), and django version(1.8.5), but the runserver reports errors like this. The database has been imported in advance.
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "django_migrations" already exists
Try this python manage.py migrate --fake
You can read more about it in official documentation
Try troubleshooting Initial migrations using --fake-initial
python manage.py migrate --fake-initial
https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-option---fake-initial
If you have an empty database you can clear all your migrations and then again run migrations and migrate command.
python manage.py makemigrations
python manage.py migrate

No such table in django

When I click in my table in http://127.0.0.1:8000/admin/, I see this error:
OperationalError at /admin/home/table/
no such table: home_table.
I ran Python manage.py makemigrations home, Python manage.py makemigrations and Python manage.py migrate but they didn't work.
If you're using sqlite then:
Try unapply all the migrations using using command:
python manage.py appname zero
Then apply the migrations command again. If it still doesn't work then delete your sqlite db and run migrations again. It will work.

Syncdb not working - django cache issue

I've dropped all tables from my postgres db. Now, while running
python manage.py syncdb
I'm getting error that abc fields doesn't exist in xyz table.
It's probably some sort of django cache issue. Error is of this format:
django.db.utils.ProgrammingError: relation "mmb_data_genre" does not exist
LINE 1: ...b_data_genre"."id", "mmb_data_genre"."genre" FROM "mmb_data_...
Any suggestions how to fix this?
Note - I'm using django 1.8.2 and
python manage.py makemigratons
or
python manage.py runserver
is throwing same error.
syncdb in django 1.8 is merely an alias for the migrate command but with the additional step of creating a superuser.
Deprecated since version 1.7: This command has been deprecated in
favor of the migrate command, which performs both the old behavior as
well as executing migrations.
But syncdb (migrate) should be executed only after you have done makemigrations [app_label] but in your case you seem to have the order in reverse.
Try
./manage.py makemigrations
./manage.py migrate

Cannot get Django 1.7 Migrations to detect proper changes to my DB.

I have a production web project running with a decent amount of data in the MySQL db. I am trying to update the database with some changes to an app called "enterlink." I've made new elements in the existing models and created new models altogether. Before this migration, I have never touched the schema of the db since originally running syncdb to create it. When I run: "python manage.py makemigrations enterlink" the below output appears(pic). My question is, why is this happening? The DB already includes all the models that it lists in the picture so why is it registering those lists of models? When I go to finish the migration by doing "python manage.py migrate" or "python manage.py migrate --fake enterlink" (pic again), I get an output shown but my database schema remains identical to the old db and any new code generates errors. Can anyone tell me what is likely the problem? I would be really appreciative of any advice. It's been very frustrating since I'm not sure what I'm missing.
What you have done is that you have ran the command python manage.py syncdb before running python manage.py makemigrations myapp and python manage.py migrate myapp. That is why syncdb created the database schema and the migration was faked because schema already exists. I will suggest to use python manage.py makemigrations myapp and python manage.py migrate myapp and not to use syncdb as its deprecated in Django 1.7.
If you change anything in your model, just run makemigrations and migrate command. Syncdb isn't necessary.
This question and relevant answers are intriguing me. Thus I want to share my experience on maintaining live database and migrations.
Tested in django1.5.5
Initializing the database:
./manage.py syncdb --noinput
./manage.py migrate
./manage.py syncdb
Now I have created the database.
Doing a migration for an app:
./manage.py schemamigration myapp --initial
./manage.py migrate myapp --fake
Now do necessary changes in your model
./manage.py schemamigration myapp --auto
./manage.py migrate myapp
Im newbie for schemamigration too, but i will explain how it works for me:
First you create app and then
./manage.py sycndb, so tables are created then you can
./manage.py makemigrations myapp --initial
so now initial migrations are created and you should apply them
./manage.py migrate myapp
now you can change your models : add,change fields, anything you want and then
./manage.py makemigrations myapp --auto
this will create migrations for changes and now you need to apply them
enter code here./manage.py migrate myapp
so this actually will create new tables in db