@重写django admin 的 user 信息后会报错的解决办法
Django在重写user信息后,即使将数据库全部删除重新使用migrete命令时也会报下面的错误
django.db.migrations.exceptions.InconsistentMigrationHistory:
Migration admin.0001_initial is applied before its dependency users.0001_initial on database 'default'.
解决办法:
1、将对应的数据库彻底删除,重新建立一个原来名称的数据库,再将APP内migrations目录删除
2、在构建表结构的时候,要先构建APP的数据库结构,再构建系统文件结构。
例如:我重写的user表结构是在 mysite内,我需要依次执行下面操作
root@python1:/home/p1# python3 manage.py migrate mysite
Operations to perform:
Apply all migrations: mysite
Running migrations:
Applying contenttypes.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0001_initial... 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 auth.0010_alter_group_name_max_length... OK
Applying auth.0011_update_proxy_permissions... OK
Applying auth.0012_alter_user_first_name_max_length... OK
Applying mysite.0001_initial... OK
root@python1:/home/p1# python3 manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, captcha, contenttypes, mysite, sessions
Running migrations:
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying admin.0003_logentry_add_action_flag_choices... OK
Applying captcha.0001_initial... OK
Applying sessions.0001_initial... OK
这样就可以生成新的user表结构,而不和原来admin里的信息重复。
我是这样解决的,不知道对你有没有帮助。