1

我正在尝试使用 Django 1.8.4 和 Python 2.7.10 创建一个项目,但我无法执行命令python manage.py runserver。我可以创建项目和应用程序,但无法运行服务器。请有人帮助我,我是 Python/Django 的新手,我不能再进步了。执行命令时,cmd 会显示下一个错误。

C:\Users\Efren\SkyDrive\UniCosta\VIII\Ingenieríade Software II\Django\PrimerProyecto>python manage.py runserver 正在执行系统检查...

系统检查未发现任何问题(0 静音)。Traceback 启动的线程中未处理的异常(最近一次调用最后一次):

包装器 fn(*args, **kwargs) 中的文件“C:\Python27\lib\site-packages\django\utils\autoreload.py”,第 225 行

文件“C:\Python27\lib\site-packages\django\core\management\commands\runserver.py”,第 112 行,inner_run self.check_migrations()

文件“C:\Python27\lib\site-packages\django\core\management\commands\runserver.py”,第 164 行,在 check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) 中

文件“C:\Python27\lib\site-packages\django\db\migrations\executor.py”,第 19 行,在init self.loader = MigrationLoader(self.connection)

文件“C:\Python27\lib\site-packages\django\db\migrations\loader.py”,第 47 行,在init self.build_graph()

文件“C:\Python27\lib\site-packages\django\db\migrations\loader.py”,第 182 行,在 build_graph self.applied_migrations = recorder.applied_migrations()

文件“C:\Python27\lib\site-packages\django\db\migrations\recorder.py”,第 59 行,在应用迁移 self.ensure_schema()

if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.光标()):

文件“C:\Python27\lib\site-packages\django\db\backends\base\base.py”,第 162 行,在光标 cursor = self.make_debug_cursor(self._cursor())

_cursor self.ensure_connection() 中的文件“C:\Python27\lib\site-packages\django\db\backends\base\base.py”,第 135 行

文件“C:\Python27\lib\site-packages\django\db\backends\base\base.py”,第 130 行,在 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

4

2 回答 2

2

It seems pretty clear that Django is unable to find your database at specified location, reasons can be,

  1. You have created django project using "sudo" or with any other other linux user than your current user, thats why your current user might not have permissions to access that database. You can check permissions of files by typing in your project's root directory,

    ls -la

  2. You have configured wrong path for database file in your settings.py

于 2017-06-09T06:58:33.590 回答
0

I believe the solution you are looking for is the following:

sudo python manage.py runserver

I was struggling with the same issue and this has finally done the trick for me.
superuser do to the rescue!

edit: If you are on windows and want to test this solution out then this link has some options: How to run 'sudo' command in windows

于 2017-01-22T20:27:47.360 回答