ERROR 1146 DJANGO没有自动创建对应表

gavinking0110 2016-11-11 09:17:41
eclipse 4.4
python 2.7
django 1.10
mysql 5.7

1、我在finnews数据库下建了finnews表格,
2、django正常运行创建了finnews_finnews表格,
3、但是由于一些别的原因,admin中无法编辑和打开finnewss表格,于是我把finnews表格和finnews_finnews表格都删了,
4、再重新migrate,可是始终无法创建finnews_finnews表格,
日志如下

D:\showwho\mysite>python manage.py makemigrations
Migrations for 'FinNews':
FinNews\migrations\0002_auto_20161111_0904.py:
- Alter field id on finnews
- Alter field shijian on finnews
- Alter field xinwen on finnews

D:\showwho\mysite>python manage.py migrate
Operations to perform:
Apply all migrations: FinNews, admin, auth, contenttypes, sessions
Running migrations:
Applying FinNews.0002_auto_20161111_0904...Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Python27\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\Python27\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "D:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "D:\Python27\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:\Python27\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:\Python27\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "D:\Python27\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:\Python27\lib\site-packages\django\db\migrations\operations\fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "D:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "D:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 683, in _alter_field
self.execute(self._create_index_sql(model, [new_field], suffix="_uniq"))
File "D:\Python27\lib\site-packages\django\db\backends\base\schema.py", line 112, in execute
cursor.execute(sql, params)
File "D:\Python27\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "D:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "D:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "D:\Python27\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "D:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 110, in execute
return self.cursor.execute(query, args)
File "D:\Python27\lib\site-packages\pymysql\cursors.py", line 166, in execute
result = self._query(query)
File "D:\Python27\lib\site-packages\pymysql\cursors.py", line 322, in _query
conn.query(q)
File "D:\Python27\lib\site-packages\pymysql\connections.py", line 835, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "D:\Python27\lib\site-packages\pymysql\connections.py", line 1019, in _read_query_result
result.read()
File "D:\Python27\lib\site-packages\pymysql\connections.py", line 1302, in read
first_packet = self.connection._read_packet()
File "D:\Python27\lib\site-packages\pymysql\connections.py", line 981, in _read_packet
packet.check_error()
File "D:\Python27\lib\site-packages\pymysql\connections.py", line 393, in check_error
err.raise_mysql_exception(self._data)
File "D:\Python27\lib\site-packages\pymysql\err.py", line 107, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.ProgrammingError: (1146, u"Table 'finnews.finnews_finnews' doesn't exist")
...全文
327 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gavinking0110 2016-11-11
  • 打赏
  • 举报
回复
现在基本确定问题源自我的app名称和表格名称的大小写敏感问题,但是加了class mega后问题还没解决
gavinking0110 2016-11-11
  • 打赏
  • 举报
回复
运行下面的代码,日志显示建立了FinNews_finnews表格,但是在mysql里面没有找到 D:\showwho\mysite>python manage.py sqlmigrate FinNews 0001 BEGIN; -- -- Create model FinNews -- CREATE TABLE `FinNews_finnews` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `shijian` date NOT NULL, `xinwen` longtext NOT NULL); COMMIT;
gavinking0110 2016-11-11
  • 打赏
  • 举报
回复
讲讲我最后的解决办法吧。 1、彻底删除相关database和dajango app; 2、重新建database,命名brandnew,重现建app,命名brandnew; 3、以上过程在往下的过程中,还会碰到各种error,所以可以无数遍重复; 4、由于有无数遍重复,记得删除brandnew下的migration文件夹中的带数字文档,并且在使用python manage.py migrate的时候加上--fake-initial。 最终搞定,经验就是不要怕删除已有成就,不要怕一切从头再来。 电脑经常会因为人为或非人为的原因产生莫名其妙的错误。 只要排除一切认为错误因素,用一遍遍的restart排除非人为因素,成功就在眼前。

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧