Django error no such table: main.auth_user__old - python

I'm creating my first Django project. I am getting an error when I press the save button after adding the data to the text fields inside the products. This is the error I get:
OperationalError at /admin/products/product/add/
no such table: main.auth_user__old
Request Method: POST
Request URL: http://127.0.0.1:8080/admin/products/product/add/
Django Version: 2.1
Exception Type: OperationalError
Exception Value:
no such table: main.auth_user__old
Exception Location: C:\Users\Ehtsham\PycharmProjects\firstproject\venv\lib\site-packages\django\db\backends\sqlite3\base.py in execute, line 296
Python Executable: C:\Users\Ehtsham\PycharmProjects\firstproject\venv\Scripts\python.exe
Python Version: 3.8.1
Python Path:
['C:\\Users\\Ehtsham\\PycharmProjects\\firstproject',
'C:\\Users\\Ehtsham\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip',
'C:\\Users\\Ehtsham\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs',
'C:\\Users\\Ehtsham\\AppData\\Local\\Programs\\Python\\Python38-32\\lib',
'C:\\Users\\Ehtsham\\AppData\\Local\\Programs\\Python\\Python38-32',
'C:\\Users\\Ehtsham\\PycharmProjects\\firstproject\\venv',
'C:\\Users\\Ehtsham\\PycharmProjects\\firstproject\\venv\\lib\\site-packages',
'C:\\Users\\Ehtsham\\PycharmProjects\\firstproject\\venv\\lib\\site-packages\\setuptools-40.8.0-py3.8.egg',
'C:\\Users\\Ehtsham\\PycharmProjects\\firstproject\\venv\\lib\\site-packages\\pip-19.0.3-py3.8.egg']
Server time: Sun, 5 Jan 2020 15:00:27 +0000
I also did migrations before:
(venv) C:\Users\Ehtsham\PycharmProjects\firstproject>python manag
e.py makemigrations
Migrations for 'products':
products\migrations\0002_offers.py
- Create model Offers
(venv) C:\Users\Ehtsham\PycharmProjects\firstproject>python manag
e.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, products, sess
ions
Running migrations:
Applying products.0002_offers... OK
I'm using Django version 2.1 and SQLite DB browser on PyCharm IDE.

It shows your django version is "Django Version:2.1"
You need to upgrade your django. if its a new project.
Please do the following steps.
step:1>> pip install Django --upgrade
step:2 >> python manage.py makemigrations
Step:3 >> python manage.py migrate
Ste:-4 >> python manage.py runserver

Related

Error when saving data in admin user interface in django

When I enter data into the admin interface to an app in Django using sqlite3 database I got this error:
OperationalError at /admin/products/product/add/
no such table: main.auth_user__old
you have to run python manage.py makemigrations and python manage.py migrate whenevr you do changes on django models.

Django: no migrations apply, but I have unapplied migrations

I deleted my database and tried to create a new one.
I did:
python manage.py makemigrations
python manage.py migrate
Then I ran python manage.py runserver and it returned
You have 2 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): social_django.
Run 'python manage.py migrate' to apply them.
Then I ran python manage.py migrate and it returned
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions, social_django
Running migrations:
No migrations to apply.
I am using django 3.0.7 and social-auth-app-django 4.0.0
The solution was to disable the environment.
I don't know why.
You can check to see which migrations have been done by viewing your database with whichever program you use to do that. And checking the django_migrations table.
The migrations that need to be applied will still be in the migrations folders for the apps that haven't been updated.
To get them migrated, assuming they're still in your installed_apps in your settings.py, simply delete the migrations (probably __init__.py) from the migrations folders and re-run :
> python manage.py makemigrations
> python manage.py migrate
run the following command on your command prompt:
1.python manage.py migrate
2.python manage.py runserver

Running migrations: No migrations to apply

I want to test django-embed-video from their official git reposiotry Django-embed-video example project.
Here are their instructions:
Example project For easy start with using django-embed-video, you can
take a look at example project. It is located in example_project
directory in root of repository.
Running example project Install requirements:
pip install -r requirements.txt
Create database:
python manage.py migrate --run-syncdb --noinput
Or, for older versions of Django:
python manage.py syncdb --noinput
Run testing server:
python manage.py runserver
Take a look at http://localhost:8000 . You can log in to
administration with username admin and password admin.
I followed all their instructions when I run.
python manage.py migrate --run-syncdb --noinput
I get the following
Operations to perform:
Synchronize unmigrated apps: embed_video, example_project, messages, posts
Apply all migrations: admin, auth, contenttypes, sessions, sites
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Running migrations:
No migrations to apply.
When I run
python manage.py runserver 8080
I get the following
Performing system checks...
System check identified no issues (0 silenced).
February 13, 2019 - 15:52:08
Django version 1.11.20, using settings 'example_project.settings'
Starting development server at http://127.0.0.1:8080/
Quit the server with CTRL-BREAK.
When I go to http://127.0.0.1:8080/ I see the following
What am I doing wrong here?

Exception Value: no such table: example_post

I have a little issue of trying the exemple file from https://github.com/zhebrak/django-statsy
OperationalError at /
no such table: example_post
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.11.5
Exception Type: OperationalError
Exception Value: no such table: example_post
Exception Location: /home/jeremie/.virtualenvs/statsy/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql, line 894
Python Executable: /home/jeremie/.virtualenvs/statsy/bin/python
Python Version: 2.7.12
Python Path:
['/home/jeremie/django-statsy',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7/plat-x86_64-linux-gnu',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-tk',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-old',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/jeremie/.virtualenvs/statsy/local/lib/python2.7/site-packages',
'/home/jeremie/.virtualenvs/statsy/lib/python2.7/site-packages',
'/home/jeremie/django-statsy']
Server time: Fri, 15 Sep 2017 15:13:34 -0500
Here is what I have done so far :
git clone https://github.com/zhebrak/django-statsy.git
mkvirtualenv statsy
cd django-statsy
workon statsy
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
I just want to enter inside the example file to see what type of result and test out the app itself. Why do I have the problem? Do you recommend this app if I am working in a project using Django 1.10 and python 2.7?
Update
┌─╼ [~/django-statsy]
└────╼ python2.7 manage.py makemigrations example
Migrations for 'example':
example/migrations/0001_initial.py
- Create model Post
┌─╼ [~/django-statsy]
└────╼ python2.7 manage.py migrate example
Operations to perform:
Apply all migrations: example
Running migrations:
Applying example.0001_initial... OK
Here is the result when I ran localhost:8000 : image
How could I test out the exemple which is given?
Based on your replies in the comments, it's looking like you haven't created the example_post database table. You'll need to add example to your list of INSTALLED_APPS in your settings file, then run through the database migration process:
./manage.py makemigrations
./manage.py migrate
If the example app isn't in INSTALLED_APPS, the database migration files won't be created and the table won't be created as a result.

django: by mistake deleted migration files from production server

By mistake I deleted all the migration files from all apps on production server.
Now running python manage.py makemigrations and then python manage.py migrate raises:
"field already exists in the database"
error for each field, What should I do ?
django version: 1.7.7
If you already migrated and then deleted.Then fake will help you
python manage.py migrate --fake
you have to fake the migration, the next command may help you:
python manage.py migrate 'name_app' 'name_migration' --fake
Example:
python manage.py migrate books 005_auto_20150505 --fake

Categories

Resources