1

I'm trying to create a project using Django 1.8.4 and Python 2.7.10, but I can't execute the command python manage.py runserver. I can create the project and apps, but can't run the server. Please somebody help me, I'm new with Python/Django and I couldn't advance more. The cmd show the next error when the command is executed.

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

phil652
  • 1,484
  • 1
  • 23
  • 48
Efren
  • 163
  • 1
  • 10
  • Did you run `python manage.py migrate` to get the database up and running? – knbk Sep 21 '15 at 19:53
  • 1
    how is your database name on settings? – Paulo Pessoa Sep 21 '15 at 19:58
  • Please share the database settings in settings.py. – Rk.. Sep 22 '15 at 14:09
  • @knbk I'm run the command and gets an error File "manage.py", line 10, in execute_from_command_line(sys.argv) ... – Efren Sep 22 '15 at 22:22
  • @PauloPessoa DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } – Efren Sep 22 '15 at 22:25
  • @RajkumarRajendran DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } – Efren Sep 22 '15 at 22:27
  • Please locate the `db.sqlite3` file and check its permissions and ownership. Ideally It should be present in your project base directory according to your setting. – avichalp Jan 22 '17 at 20:47

2 Answers2

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

Akash Wankhede
  • 618
  • 6
  • 15
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

Community
  • 1
  • 1
Marcelo
  • 109
  • 6