码迷,mamicode.com
首页 > 数据库 > 详细

django迁移文件时出错,然后发现只迁移成功一半的sql表格,另外一半重新执行命令无法迁移成功,解决方法

时间:2020-07-22 11:10:04      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:turn   lib   size   read   super   etc   stat   first   err   

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\core\management\__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\core\management\base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\core\management\commands\migrate.py", line 202, in handle
    post_migrate_state = executor.migrate(
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\migrations\operations\models.py", line 97, in database_forwards
    schema_editor.create_model(model)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\base\schema.py", line 303, in create_model
    self.execute(sql, params or None)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\base\schema.py", line 120, in execute
    cursor.execute(sql, params)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\utils\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
    return self.cursor.execute(query, args)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\cursors.py", line 170, in execute
    result = self._query(query)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\cursors.py", line 328, in _query
    conn.query(q)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result
    result.read()
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\connections.py", line 684, in _read_packet
    packet.check_error()
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "D:\python_learn\meiduo_project\env\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
django.db.utils.InternalError: (1050, "Table ‘tb_content‘ already exists")

未迁移成功的表格也会显示已经迁移成功

删migrations目录、django_migrations表中的相应的迁移记录

然后执行

python manage.py makemigrations
python manage.py migrate

django迁移文件时出错,然后发现只迁移成功一半的sql表格,另外一半重新执行命令无法迁移成功,解决方法

标签:turn   lib   size   read   super   etc   stat   first   err   

原文地址:https://www.cnblogs.com/sewen-H/p/13358347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!