Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line utility.execute() File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv self.execute(*args, **cmd_options) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\base.py", line 364, in execute output = self.handle(*args, **options) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle loader.check_consistent_history(connection) File "E:\virtualenv\djangoFrame-V3Y6g1nz\lib\site-packages\django\db\migrations\loader.py", line 299, in check_consistent_history connection.alias, django.db.migrations.exceptions.InconsistentMigrationHistory: Migration user.0002_user_create_time is applied before its dependency user.0001_initial on database 'default'.
python manage.py makemigrations
:根据我们自定义的模型生成对应的迁移脚本python manage.py migrate
:发生了两步操作:一:将迁移脚本转换成sql语句,然后再去数据库中执行转换后的sql语句。二:如果转换后的sql语句没有错误,则会此条迁移记录保存到数据库中的django_migrations表中数据库django_migrations表中保存的迁移版本与django项目目录下的迁移版本不一致
首先找到数据库表中的版本与项目目录下的哪个版本不一致,确定版本不一致的app,解决问题的第一步就完成了
详细的解决报错的步骤:
①:将数据django_migrations表下的有关找到的不一致的app的迁移记录全部删除
②:删除django项目目录下user app的migrations目录的全部迁移脚本
③:将django项目的user app的模型修改的与数据库表中保存的字段属性相同!!!
④:使用迁移命令生成对应app的迁移脚本:python manage.py makemigrations user
出现上述情况即为生成对应的迁移脚本成功!!
⑤:使用命令将初始化的脚本标记为已经映射,然后再次修改django项目下的app模型文件就不会发生报错!!!
出现上述信息即为完美解决此报错!!!然后你就可以修改django项目下的模型,再次生成迁移脚本,执行迁移命令时就不会出现上述的报错了!!