Python/Django 运行 开发服务器
Python/Django run development server
我正在尝试使用 Django 1.8.4 和 Python 2.7.10 创建一个项目,但我无法执行命令 python manage.py runserver
。我可以创建项目和应用程序,但不能 运行 服务器。
请有人帮助我,我是 Python/Django 的新手,我不能再进步了。
cmd 在执行命令时显示下一个错误。
C:\Users\Efren\SkyDrive\UniCosta\VIII\Ingeniería de Software
II\Django\PrimerProyecto>python manage.py runserver Performing system
checks...
System check identified no issues (0 silenced). Unhandled exception in
thread started by Traceback (most
recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py",
line 225, in wrapper
fn(*args, **kwargs)
File
"C:\Python27\lib\site-packages\django\core\management\commands\runserver.py",
line 112, in inner_run
self.check_migrations()
File
"C:\Python27\lib\site-packages\django\core\management\commands\runserver.py",
line 164, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File
"C:\Python27\lib\site-packages\django\db\migrations\executor.py", line
19, in init
self.loader = MigrationLoader(self.connection)
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py",
line 47, in init
self.build_graph()
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py",
line 182, in build_graph
self.applied_migrations = recorder.applied_migrations()
File
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line
59, in applied_migrations
self.ensure_schema()
File
"C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line
49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File
"C:\Python27\lib\site-packages\django\db\backends\base\base.py", line
162, in cursor
cursor = self.make_debug_cursor(self._cursor())
File
"C:\Python27\lib\site-packages\django\db\backends\base\base.py", line
135, in _cursor
self.ensure_connection()
File
"C:\Python27\lib\site-packages\django\db\backends\base\base.py", line
130, in ensure_connection
self.connect()
File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in
exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File
"C:\Python27\lib\site-packages\django\db\backends\base\base.py", line
130, in ensure_connection
self.connect()
File
"C:\Python27\lib\site-packages\django\db\backends\base\base.py", line
119, in connect
self.connection = self.get_new_connection(conn_params)
File
"C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py",
line 204, in get_new_connection
conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file
我相信您正在寻找的解决方案如下:
sudo python manage.py runserver
我一直在为同样的问题而苦苦挣扎,这终于为我解决了问题。
超级用户做来救援!
编辑: 如果您在 windows 上并且想测试这个解决方案,那么这个 link 有一些选择:
How to run 'sudo' command in windows
很明显 Django 无法在指定位置找到您的数据库,原因可能是,
您使用 "sudo" 或与当前用户以外的任何其他 linux 用户创建了 django 项目,这就是为什么您的当前用户可能没有访问该数据库的权限.您可以通过输入项目的根目录来检查文件的权限,
ls -la
您在 settings.py
中为数据库文件配置了错误的路径
我正在尝试使用 Django 1.8.4 和 Python 2.7.10 创建一个项目,但我无法执行命令 python manage.py runserver
。我可以创建项目和应用程序,但不能 运行 服务器。
请有人帮助我,我是 Python/Django 的新手,我不能再进步了。
cmd 在执行命令时显示下一个错误。
C:\Users\Efren\SkyDrive\UniCosta\VIII\Ingeniería de Software II\Django\PrimerProyecto>python manage.py runserver Performing system checks...
System check identified no issues (0 silenced). Unhandled exception in thread started by Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 112, in inner_run self.check_migrations()
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 164, in check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 19, in init self.loader = MigrationLoader(self.connection)
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 47, in init self.build_graph()
File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", line 182, in build_graph self.applied_migrations = recorder.applied_migrations()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 59, in applied_migrations self.ensure_schema()
File "C:\Python27\lib\site-packages\django\db\migrations\recorder.py", line 49, in ensure_schema if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 162, in cursor cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 135, in _cursor self.ensure_connection()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 130, in ensure_connection self.connect()
File "C:\Python27\lib\site-packages\django\db\utils.py", line 97, in exit six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 130, in ensure_connection self.connect()
File "C:\Python27\lib\site-packages\django\db\backends\base\base.py", line 119, in connect self.connection = self.get_new_connection(conn_params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py", line 204, in get_new_connection conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file
我相信您正在寻找的解决方案如下:
sudo python manage.py runserver
我一直在为同样的问题而苦苦挣扎,这终于为我解决了问题。
超级用户做来救援!
编辑: 如果您在 windows 上并且想测试这个解决方案,那么这个 link 有一些选择: How to run 'sudo' command in windows
很明显 Django 无法在指定位置找到您的数据库,原因可能是,
您使用 "sudo" 或与当前用户以外的任何其他 linux 用户创建了 django 项目,这就是为什么您的当前用户可能没有访问该数据库的权限.您可以通过输入项目的根目录来检查文件的权限,
ls -la
您在 settings.py
中为数据库文件配置了错误的路径