Django-没有这样的表: main.auth_user__ old

我从官方的 Django 文档跟随 第一个应用程序教程,并且在尝试保存通过管理页面所做的一些更改时得到了这个错误。我对此做了一些研究,但是我能够找到的可能的解决方案,比如迁移数据库,根本不起作用。如果你想看我代码中的某些特定部分,请告诉我。

错误如下:

OperationalError/admin/poll/questions/1/change/no such table: Auth _ user _ _ old Request Method: POST Request 网址: http://127.0.0.1:8000/admin/polls/question/1/change/姜戈 版本: 2.1.4异常类型: OperationalError 异常值: no 这样的表: main.auth _ user _ _ old 异常 位置:/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/sqlite3/base.py 在执行时,第296行 Python 可执行文件:/Users/gfioravante/Projects/test _ app/ta _ env/bin/python3 Python 版本: 3.7.1 Python Path:
[/Users/gfioravante/Projects/test _ app/test _ app’, ’/usr/local/Cellar/python/3.7.1/Frances/Python. Framework/Versions/3.7/lib/python37. zip’, ’/usr/local/Cellar/python/3.7.1/Frances/Python. Framework/Versions/3.7/lib/python3.7’, “/usr/local/Cellar/python/3.7.1/Framework/Python.Framework/Versions/3.7/lib/python3.7/lib-dynload”, “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package”] 服务器时间: 2018年12月5日星期三16:45:00 + 0000

还有追踪记录:

环境:

请求方法: POST 请求 URL: Http://127.0.0.1:8000/admin/polls/question/1/change/

Django 版本: 2.1.4 Python 版本: 3.7.1已安装的应用程序: [‘ polls.apps. PollsConfig’,‘ django.Contrib.admin’, ‘ django. Contrib.auth’,‘ django. Contrib.contenttype’, “ django 贡献会话”“ django 贡献信息” 已安装的中间件: 中间件,安全,安全中间件, “ django. Contrib.sessions.middleware. SessionMiddleware” “ django 中间件,通用中间件” 中间件, 中间件, 中间件, ‘ django. midware.clickjacking.XFrameOptionsMiddleware’]

追溯:

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” In _ execute 执行(sql,params)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/sqlite3/base.py” 执行 执行(self,query,params)

上面的异常(没有这样的表: main.auth _ user _ _ old)是 下列例外情况的直接原因:

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/core/handlers/exction.py” 在内心深处 Response = get _ response (request)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/core/handlers/base.py” 得到回应 126.Response = self. process _ eption _ by _ Middle ware (e,request)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/core/handlers/base.py” 得到回应 124.Response =  包裝 _ callback (request,* callback _ args,* * callback _ kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/options.py” 用包装纸包着 返回 self. admin _ site. admin _ view (view)(* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/utils/decorators.py” In _  包裝 _ view 142.Response = view _ func (request,* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/views/decators/cache.py” In _  包裝 _ view _ func Response = view _ func (request,* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/sites.py” 返回视图(request,* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/options.py” 在 change _ view 中 返回 self. changeform _ view (request,object _ id,form _ url,tra _ context)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/utils/decorators.py” 包装 45. return bound _ method (* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/utils/decorators.py” In _  包裝 _ view 142.Response = view _ func (request,* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/options.py” 在 changeform _ view 中 返回 self _ changeform _ view (request,object _ id,form _ url,tra _ context)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/options.py” In _ change _ view 1571年。Log _ change (request,new _ object,change _ message)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/options.py” 在 log _ change 中 Change _ message = message,

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/Contrib/admin/mods.py” In log _ action 变更消息 = 变更消息,

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/manager. py” 在 manager _ method 中 82.Return getattr (self. get _ queryset () ,name)(* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/query.py” 创造 Save (force _ insert = True,using = self. db)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/base.py” 保存 718.Force _ update = force _ update,update _ fields = update _ fields)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/base.py” 在 save _ base 中 748.Update = self _ save _ table (raw,cls,force _ insert,force _ update,using,update _ fields)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/base.py” In _ save _ table Result = self _ do _ insert (cls. _ base _ manager,using,fields,update _ pk,raw)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/base.py” 插入 869.使用; 使用

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/manager. py” 在 manager _ method 中 82.Return getattr (self. get _ queryset () ,name)(* args,* * kwargs)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/query.py” 插入 1136. return query.get _ Editor (using = using) . execute _ sql (return _ id)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/model/sql/comper.py” 执行 _ sql 执行(sql,params)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” 执行 100. return super () . execute (sql,params)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” 执行 返回 self _ execute _ with _ wrappers (sql,params,many = False,Executive = self _ execute)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” In _ execute _ with _ wrappers 返回执行器(sql,params,many,context)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” In _ execute 执行(sql,params)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/utils.py” 在 出口 89.提高 dj _ exc _ value。With _ traceback (traceback) from exc _ value

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/utils.py” In _ execute 执行(sql,params)

档案 “/Users/gfioravante/Projects/test _ app/ta _ env/lib/python3.7/site-package/django/db/backend/sqlite3/base.py” 执行 执行(self,query,params)

异常类型: OperationalError at/admin/poll/questions/1/change/ 异常值: 没有这样的表: main.auth _ user _ _ old

106414 次浏览

I just came across this myself, it looks to be related to https://code.djangoproject.com/ticket/29182. For now, you can just downgrade your version of sqlite to a version prior to 2.6 (e.g. 2.5.1)

Open => /YourAppFolder/migrations/ You would to see the migrating files just like '0001_initial.py' delete all of these files. And run the follwing command 1- python manage.py makemigrations 2- python manage.py migrate Hope, it must solve your problem

Steps:

  1. Uninstall current Django from your ENV. Just delete the folder "anaconda3/envs/yourenv/lib/python3.7/site-packages/Django all versions..

    Note: Only for Anaconda users, other users should figure out how to uninstall a package from your ENV.

  2. Go to https://github.com/django/django.

  3. Download the repo as zip file.

  4. Extract zip.

  5. Switch to your ENV.

  6. Enter the extracted folder.

  7. Run "python setup.py install" And install Django.

  8. Delete your previous db.sqlite3 file. Now apply the migrations again to create a new db.sqlite3 file.

    Note: I don't know how to fix previous dbfile and prevent data loss. So please tell me if you know.

  9. Run Server.

Congrats! It works fine now.

Update to latest django in January from the official Django release.

The problem is caused by the modified behaviour of the ALTER TABLE RENAME statement in SQLite 3.26.0 (see compatiblity note). They also introduced the PRAGMA legacy_alter_table = ON statement in order to maintain the compatibility with previous versions. The upcoming Django release 2.1.5 utilizes the previously mentioned statement as a hotfix. It's expected on January 1, 2019.

For others who don't want to downgrade any software, you can head into your settings.py file and in the DATABASES dict, you can replace .sqlit3 with .postgresql, and right underneath it change the db.sqlit3 to db.sql. This switches your default db to using postgreSQL.

In doing so, you'll need to pip install psycopg2.

Delete your db.sqlite3 file (if you have one/don't care about losing what's in it) and everything else that isn't the __init__.py file in your app's migration folder. Once you've done all of that, you can run python manage.py makemigrations and python manage.py migrate and then it should work :)

Hope I was able to help someone!

Same thing is happened to me, very frustrating. I use anaconda for my environments, I found that I couldn't remove sqlite without immediately reinstalling the most up to date version of sqlite. Trying an older version of django also didn't seem to work. The only solution that has worked for me is by using a PostgreSQL database. It's certainly not ideal but I am planning on utilising the PostgreSQL database in the future so this wasn't a complete waste of time. If you find yourself in the same place as I was then this video may be helpful if you want to know how to connect the PostgreSQL database with your django project.

You'll need to install the postgreSQL database before actually making the changes in settings.py, the installation is more of less clicking Next on all the options. However, remember the username and password you use during installation.

There are just 4 things I did on command line and it fixed mine.

  1. ctrl + c (stop server)
  2. py manage.py makemigrations
  3. py manage.py migrate
  4. py manage.py runserver (start server)

I solved the problem by upgrading Django from 2.1.4 to 2.1.5 by running

pip install --upgrade django==2.1.5

but I had to rebuild the project anew, because the bug seems to be somehow related to the objects I inserted into the database by using the old version of Django.


UPDATE:

Instead of deleting the entire project, it was sufficient to delete only the database. And then to run

python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

go to this folder django/db/backends/sqlite3

backup schema.py file to another folder

open the original schema.py in a text editor

there you can see a code snippet like

    def __enter__(self):
# Some SQLite schema alterations need foreign key constraints to be
# disabled. Enforce it here for the duration of the schema edition.
if not self.connection.disable_constraint_checking():
raise NotSupportedError(
'SQLite schema editor cannot be used while foreign key '
'constraint checks are enabled. Make sure to disable them '
'before entering a transaction.atomic() context because '
'SQLite3 does not support disabling them in the middle of '
'a multi-statement transaction.'
)
self.connection.cursor().execute('PRAGMA legacy_alter_table = ON')
return super().__enter__()

comment them and paste the following code snippet

     def __enter__(self):
# Some SQLite schema alterations need foreign key constraints to be
# disabled. Enforce it here for the duration of the transaction.
self.connection.disable_constraint_checking()
self.connection.cursor().execute('PRAGMA legacy_alter_table = ON')
return super().__enter__()

This worked for me. (the backup for the schema.py is in case the work go wrong ; D )

for more info

https://github.com/django/django/pull/10733/commits/c8ffdbe514b55ff5c9a2b8cb8bbdf2d3978c188f#diff-0c8f495bfee773ab7b5409533bd6d7ef

I had the same issue except that I had 2 sqlite databases and custom database router. I managed to get it working by downgrading Django to 1.11.20 and no need to recreate the databases.

Get rid of this issue easily maintaining the following steps:

  1. keep django version 2.1.5 (the issue addressed in this version) pip install django==2.1.5
  2. Delete the SQLite db
  3. Migrate again python manage.py makemigrations and then python manage.py migrate
  4. Start the server python manage.py runserver

DONE!

For those who cannot resolve this error with above answers, if you had made your app with its name “main”, this error may occur cause of same app name issue. So try to change your app name “main” to another.

you need to upgrade Django, this issue has been fixed in this PR https://github.com/django/django/pull/10733

I solved the problem by changing some of my models. I had one named project and one named projects. The database tables got confused and threw me this error.

Just did this and it resolved the problem:

pip install Django --upgrade

Then:

python manage.py migrate


python manage.py makemigrations app


python manage.py migrate

For the above problem and solution is:

1) Go to the terminal and type in pip install django==2.1.7 or the latest version of django

2) After the installation,In the terminal type in python manage.py makemigrations,and then python manage.py migrate

3) In the terminal,Start the server with code python manage.py runserver

4) Login to the admin server with the password and the add the product,It will successfully add the product.

I have solved this issue using below :

1) Delete the db.sqlit3

2) app's directory delete everything in pycache

3) manage.py makemigrations, manage.py migrate, manage.py createsuperuser and then manage.py runserver.

django-2.2.7
This worked for me -

1) Delete db.sqlite3.
2) Within each app, within the migrations folder, delete everything other than __init__.py .
3) Within each app,delete __pycache__ folder.

I am not sure if you had to do it for all apps or just the concerned app, but this worked for me.

I had the same issue and fixed it by doing the below:

1) Get the latest django version

2) get the latest SQL Lite version

3) delete db.sqlite3 file from your project

4) Make a small change to the models.py (e.g. change the size of a field)

5) generate a new db.sqllite3 file by running the makemigrations & migrate commands

6) import the newly created db.sqllite3 file into SQL Lite

Here is what I did to solve this problem:

  1. Go to the virtual environment and install django@2.1.7

    pip install django==2.1.7
    
  2. Delete the db.sqlite3 file in your root folder.

  3. Create the new db.sqlite3 in your root folder.
  4. Re-run migrations:

    python3 manage.py makemigrations
    
    
    python3 manage.py migrate
    

Now it should be working all right.

Even after upgrading to the latest Django 2.2.12 and running either migrate or the official database rebuild script, I got the same error with __old_: django.db.utils.IntegrityError: The row in table 'djangocms_blog_post_translation' with primary key '2' has an invalid foreign key: djangocms_blog_post_translation.master_id contains a value '2' that does not have a corresponding value in djangocms_blog_post__old.id.

Here's my hack:

  1. dump the database contents to sql: sqlite3 my_db.db .dump > my_db.sql
  2. run a regex over the sql output, replacing __old" ("id") with " ("id") DEFERRABLE INITIALLY DEFERRED
  3. delete the old database file
  4. load the modified sql into a new database: sqlite3 my_db.db < my_db.sql
  5. ??? & profit

I installed/downgraded django to 2.2 version ,this removed django 3.x

pip install django==2.2

and then I deleted db.sqlite file and then

I tried

python manage.py makemigrations,
python manage.py migrate
python manage.py creatingsuperuser.
  1. First, stop the server and delete db.sqlite3.

  2. Then, you need to run:

    python manage.py makemigrations
    python manage.py migrate

  3. After running this command you need to create super user. To Create Super User, run:
    python manage.py createsuperuser
    Enter the super user details there.

  4. Run your server again.

There you go.

First, update django version:

pip install django --upgrade

then

./manage.py makemigration
./manage.py migrate
./manage.py runserver


for me, it was from my django version (that was 2.1) install higher version (I used 2.1.5 for some reasons) ** delete db.sqlite3, and everything in migration folder except init.py run command:

pip install django==2.1.5 --upgrade
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

keep django version 2.1.5

This issue is adressed only in this version of Django
  • pip install django==2.1.5
  • Delete the SQLite db
  • Run migration
  • Start the server python manage.py runserver

This solves the above issue

  1. Upgrade Django pip install Django --upgrade

  2. Delete the db.sqlite3 file the root folder of your project.

  3. Create the new db.sqlite3 in your root folder by re-running migrations. python3 manage.py makemigrations

  4. Migrate python3 manage.py migrate

It may work with just this or you may need to create a new superuser if it was deleted.

  1. Check for your superuser using
python manage.py shell
from django.contrib.auth.models import User
User.objects.filter(is_superuser=True)

If <QuerySet []> appears there is no user. Else check if your user exists.

  1. If your user does not exist create one using python manage.py createsuperuser

Please check if you haven't deleted the migration folder from your app if deleted try to restore the folder and remove migration files or if deleted permanently create app and copy paste your work and

then

1. Delete db.sqlite3
2. python manage.py makemigrations
3. python manage.py migrate
4. python manage.py createsuperuser

HTH :)

  1. Delete db.sqlite3
  2. makemigrations & migrate
  3. Create new super user

This works for me

Note: Do not follow this trick if you have some personal data in Sqlite3 DB as you're going to delete Sqlite3 DB

I know many answers are given to this question but only this trick help me to solve this issue as I'm beginner at python and learning Django.

  1. Stopped the django webserver running, Ctrl-C
  2. Delete the db.sqlite3
  3. Uninstalled Django old verison
  4. Install latest version of Django with “pip install django”
  5. Delete all migrations from all apps of your project

Now run these commands in terminal

  1. python manage.py makemigrations
  2. python manage.py migrate
  3. python manage.py createsuperuser ( provide super-user credentials )
  4. python manage.py runserver

Now finally login to admin panel with updated super-user's credentials and try to add record.

Same suggestions at this link by someone