解决no such table: main.auth_user__old

解决no such table: main.auth_user__old_第1张图片
解决办法:

原Django版本:2.0.5

升级Django的版本至2.1.7,

命令:pip install Django –upgrade

可以使用python -m django –version查看版本号,更新Django版本且备份好数据库里的数据后,删除app下的migrations文件夹,删除db.sqlite3,重新进行数据库迁移。

#先迁移默认的app

python manage.py migrate

#再迁移自己的app
python manage.py makemigrations polles
python manage.py migrate polles

数据库迁移以后,再创建超级用户,在后台的Django administration,执行添加修改操作。

详细操作:

(document) [root@hadoop1 mysite]#  python -m django --version
2.0.5
(document) [root@hadoop1 mysite]# pip install Django --upgrade
Collecting Django
  Downloading https://files.pythonhosted.org/packages/c7/87/fbd666c4f87591ae25b7bb374298e8629816e87193c4099d3608ef11fab9/Django-2.1.7-py3-none-any.whl (7.3MB)
    100% |████████████████████████████████| 7.3MB 62kB/s 
Requirement already satisfied, skipping upgrade: pytz in /root/anaconda3/envs/document/lib/python3.6/site-packages (from Django) (2018.9)
Installing collected packages: Django
  Found existing installation: Django 2.0.5
    Uninstalling Django-2.0.5:
      Successfully uninstalled Django-2.0.5
Successfully installed Django-2.1.7
(document) [root@hadoop1 mysite]# python manage.py makemigrations
No changes detected
(document) [root@hadoop1 mysite]# python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
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 sessions.0001_initial... OK
(document) [root@hadoop1 mysite]# python manage.py makemigrations polles
Migrations for 'polles':
  polles/migrations/0001_initial.py
    - Create model Choice
    - Create model Question
    - Add field question to choice
(document) [root@hadoop1 mysite]# python manage.py migrate polles
Operations to perform:
  Apply all migrations: polles
Running migrations:
  Applying polles.0001_initial... OK
(document) [root@hadoop1 mysite]# python manage.py createsuperuser
Username (leave blank to use 'root'): root
Email address: [email protected]
Password: 
Password (again): 
Superuser created successfully.

你可能感兴趣的:(python_web)