Django-해당 테이블 없음 : main.auth_user__old
공식 Django 문서 의 첫 번째 앱 자습서 를 따르고 있었는데 관리자 페이지를 통해 변경 한 사항을 저장하려고 할 때이 오류가 발생했습니다. 나는 그것에 대해 약간의 조사를했지만 db 마이그레이션과 같은 가능한 솔루션은 작동하지 않습니다. 내 코드의 특정 부분을보고 싶다면 알려주세요.
다음은 오류입니다.
OperationalError at / admin / polls / question / 1 / change / no such table : main.auth_user__old Request Method : POST Request URL : http://127.0.0.1:8000/admin/polls/question/1/change/ Django 버전 : 2.1.4 예외 유형 : OperationalError 예외 값 : 해당 테이블 없음 : main.auth_user__old 예외 위치 : /Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/sqlite3/base .py in execute, line 296 Python 실행 파일 : / Users / gfioravante / Projects / test_app / ta_env / bin / python3 Python 버전 : 3.7.1 Python 경로 :
[ '/ Users / gfioravante / Projects / test_app / test_app', '/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/ usr / local /Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7 ','/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/ lib / python3.7 / lib-dynload ','/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages '] 서버 시간 : Wed, 5 Dec 2018 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.contenttypes', 'django .contrib.sessions ','django.contrib.messages ','django.contrib.staticfiles '] 설치된 미들웨어 : ['django.middleware.security.SecurityMiddleware ','django.contrib.sessions.middleware.SessionMiddleware ','django .middleware.common.CommonMiddleware ','django.middleware.csrf.CsrfViewMiddleware ','django.contrib.auth.middleware.AuthenticationMiddleware ','django.contrib.messages.middleware.MessageMiddleware ','django.middleware.clickjacking.XFrameOptionsMiddleware ']
역 추적:
_execute 85의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"파일. return self.cursor.execute (sql, params)
파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py"실행 296. return Database.Cursor.execute (self, query, 매개 변수)
위의 예외 (해당 테이블 없음 : main.auth_user__old)는 다음 예외의 직접적인 원인이었습니다.
내부 34에있는 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/core/handlers/exception.py"파일. response = get_response (request)
_get_response 126의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/core/handlers/base.py"파일. response = self.process_exception_by_middleware (e, request)
_get_response 124의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/core/handlers/base.py"파일. response = Wrap_callback (request, * callback_args, ** callback_kwargs)
래퍼 604의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/options.py"파일. return self.admin_site.admin_view (view) (* args, ** kwargs)
_wrapped_view 142의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/utils/decorators.py"파일. response = view_func (request, * args, ** kwargs)
_wrapped_view_func 44의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/views/decorators/cache.py"파일. response = view_func (request, * args, ** kwargs)
내부 223의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/sites.py"파일. return view (request, * args, ** kwargs)
change_view 1640의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/options.py"파일. return self.changeform_view (request, object_id, form_url, extra_context)
_wrapper 45의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/utils/decorators.py"파일. return bound_method (* args, ** kwargs)
_wrapped_view 142의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/utils/decorators.py"파일. response = view_func (request, * args, ** kwargs)
changeform_view 1525의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/options.py"파일. return self._changeform_view (request, object_id, form_url, extra_context)
_changeform_view 1571의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/options.py"파일. self.log_change (request, new_object, change_message)
log_change 826의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/options.py"파일. change_message = message,
log_action 35의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/contrib/admin/models.py"파일. change_message = change_message,
manager_method 82의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/manager.py"파일. return getattr (self.get_queryset (), name) (* 인수, ** kwargs)
create 413의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/query.py"파일. obj.save (force_insert = True, using = self.db )
save 718의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/base.py"파일. force_update = force_update, update_fields = update_fields)
save_base 748의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/base.py"파일. updated = self._save_table (raw, cls, force_insert, force_update , 사용, update_fields)
_save_table 831의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/base.py"파일. result = self._do_insert (cls._base_manager, using, fields , update_pk, 원시)
파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/base.py"in _do_insert 869. using = using, raw = raw)
manager_method 82의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/manager.py"파일. return getattr (self.get_queryset (), name) (* 인수, ** kwargs)
_insert 1136의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/query.py"파일. return query.get_compiler (using = using) .execute_sql (return_id )
execute_sql 1289의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py"파일. cursor.execute (sql, params)
파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"실행 100. return super (). execute (sql, params)
execute 68의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"파일. return self._execute_with_wrappers (sql, params, many = False, executor = self._execute)
파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"in _execute_with_wrappers 77. return executor (sql, params, many, context)
_execute 85의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"파일. return self.cursor.execute (sql, params)
89 번 출구에있는 파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/utils.py" . exc_value에서 dj_exc_value.with_traceback (traceback)을 올립니다.
_execute 85의 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/utils.py"파일. return self.cursor.execute (sql, params)
파일 "/Users/gfioravante/Projects/test_app/ta_env/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py"실행 296. return Database.Cursor.execute (self, query, 매개 변수)
예외 유형 : OperationalError at / admin / polls / question / 1 / change / 예외 값 : 해당 테이블 없음 : main.auth_user__old
나는 방금 이것을 직접 보았고 https://code.djangoproject.com/ticket/29182 와 관련이있는 것 같습니다 . 지금은 sqlite 버전을 2.6 이전 버전 (예 : 2.5.1)으로 다운 그레이드 할 수 있습니다.
문제는 ALTER TABLE RENAME
SQLite 3.26.0 의 수정 된 동작으로 인해 발생합니다 ( 호환성 참고 사항 참조 ). 또한 PRAGMA legacy_alter_table = ON
이전 버전과의 호환성을 유지하기 위해 성명서를 도입했습니다 . 곧 출시 될 Django 릴리스 2.1.5 에서는 이전에 언급 한 설명을 핫픽스로 사용합니다. 2019 년 1 월 1 일에 예정되어 있습니다.
이 폴더로 이동 django / db / backends / sqlite3
'schema.py'파일을 다른 폴더에 백업
텍스트 편집기에서 원본 schema.py를 엽니 다.
다음과 같은 코드 스 니펫을 볼 수 있습니다.
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__()
주석을 달고 다음 코드 조각을 붙여 넣으십시오.
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__()
이것은 나를 위해 일했습니다. (schema.py의 백업은 작업이 잘못되는 경우입니다. D)
더 많은 정보를 위해서
감사합니다
다음 단계를 유지하여이 문제를 쉽게 제거하십시오.
- django 버전 2.1.5 유지 (이 버전에서 해결 된 문제)
pip install django==2.1.5
- SQLite db 삭제
- 다시 마이그레이션
python manage.py makemigrations
한 다음python manage.py migrate
- 서버 시작
python manage.py runserver
끝난!
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.
I solved the problem by upgrading Django from 2.1.4 to 2.1.5, but I had to rebuild the project anew, because the bug seems to be somehow related to the obgjects I inserted into the database by using the old version of Django.
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!
Just only did this and i resolved this problem
`pip install Django --upgrade`
Then
python manage.py migrate
python manage.py makemigrations app
python manage.py migrate
And the end
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
if you don't wanna change your Django version then Database has to be the change. Use PostgreSQL my recommendations. The problem would be resolve after makemigrations and migrate.
Steps:
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.
Go to Github.com/django/django.
Download the repo as zip file.
Extract zip.
Switch to your ENV.
Enter the extracted folder.
Run "python setup.py install" And install Django.
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.
- Run Server.
Congrats! It works fine now.
Update to latest django in January from the official Django release.
I just tried to solve the issue using the latest version of Django but the problem still remains. Till the time they don't debug this issue with Django and Sqlite3 use the older versions of Django You may consider using version 1.10.5(using command pip install --upgrade django==1.10.5)
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.
What you can do is that simply just go to the database using sqlite3 browser and change the referencing table using the respective attribute from auth_user__old to auth_user. It worked for me and my project is working fine.
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.
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.
Yes I've got same error on Django 2.1.4
OperationalError (No such table: main.auth_user__old)
I deleted Django 2.1.4 install Django 1.11.16 the problem solved
Install Django 1.11.16 isn't useful for me. It'll show "ModuleNotFoundError" and "FileNotFoundError". Then I open the file "db.sqlite3", copy the table "auth_user" and "django_content_type" with struct and data, change table name to "auth_user__old" and "django_content_type__old". It worked! I hope It's useful to the confused.
There are just 4 things I did on command line and it fixed mine.
- ctrl + c (stop server)
py manage.py makemigrations
py manage.py migrate
py manage.py runserver
(start server)
Please downgrade django version to 1.5 or in case if you do not want to downgrade version then you can change schema.py locally, apply patch and run makemigrations + migrate command but its not recommended.
Upgrade the version of Django from 2.1 to higher. I upgraded to 2.1.8. Worked for me!
Cheers.....
ReferenceURL : https://stackoverflow.com/questions/53637182/django-no-such-table-main-auth-user-old
'programing' 카테고리의 다른 글
초기 값과 설정되지 않은 값의 차이점은 무엇입니까? (0) | 2021.01.15 |
---|---|
IntelliJ의 멋진 ≠ (같지 않음) 연산자 활성화 (0) | 2021.01.15 |
트랜잭션 내에서 테이블 자르기 (0) | 2021.01.15 |
malloc 구현은 해제 된 메모리를 시스템에 반환합니까? (0) | 2021.01.15 |
멤버 이니셜 라이저에서 'this'를 사용할 수없는 이유는 무엇입니까? (0) | 2021.01.15 |