执行 python manage.py runserver 0.0.0.0:8080 时报错,如何解决?

LionelShen 发布于 2016/09/26 17:42
阅读 1K+
收藏 0
# python manage.py runserver 0.0.0.0:8080
Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x2af27879d578>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check_migrations()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 437, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 20, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 52, in __init__
    self.build_graph()
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 203, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
    self.ensure_schema()
  File "/usr/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 56, in ensure_schema
    with self.connection.schema_editor() as editor:
  File "/usr/local/lib/python2.7/site-packages/django/db/backends/sqlite3/schema.py", line 25, in __enter__
    self._initial_pragma_fk = c.fetchone()[0]

TypeError: 'NoneType' object has no attribute '__getitem__'

环境说明:

# python
Python 2.7.12 (default, Sep 27 2016, 00:24:04)

# which python
/usr/local/bin/python

# which django-admin
/usr/local/bin/django-admin


加载中
0
LionelShen
LionelShen

等了2天,没有人回答,我自己搞定了,根据错误“self.check_migrations()”和(connections[DEFAULT_DB_ALIAS])来判断,是因为连接数据库的问题。

解决办法:我重新配置了settings.py文件,把里面默认django.db.backends.sqlite3改成了django.db.backends.mysql引擎。然后又安装了MySQL-python。创建了mysql的数据库。最终启动不再报错,顺利执行。

上面就是我自己搞定的方法,贴出来给大家一个帮助吧。

0
分享一下
分享一下
比较基本的debug,所以没有人回答
返回顶部
顶部