-3

I'm not sure if removed some pycache files and it messed my website up or if me pulling some files from git has changed my folders about but I'm getting database connect issues.

I have tried makemigrations, migrate and runserver and I'm getting the same error each time. I can't uninstall wagtail or django as it comes up failed to create process. I'm getting the horrible feeling it might be time to scratch the project and start again.

Here is the error

self.connection = self.get_new_connection(conn_params)
  File "..\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 194, in get_new_connection
    conn = Database.connect(**conn_params)
sqlite3.OperationalError: unable to open database file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "..\threading.py", line 926, in _bootstrap_inner
    self.run()
File "..\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "..\autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "..\runserver.py", line 120, in inner_run
    self.check_migrations()
  File "..\base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "..\executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "..\loader.py", line 49, in __init__
    self.build_graph()
  File "..\loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "..\recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "..\recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "..\base.py", line 256, in cursor
    return self._cursor()
  File "..\base.py", line 233, in _cursor
    self.ensure_connection()
  File "..\base.py", line 217, in ensure_connection
    self.connect()
  File "..\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "..\base.py", line 217, in ensure_connection
    self.connect()
  File "..\venv\lib\site-packages\django\db\backends\base\base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "..\venv\lib\site-packages\django\db\backends\sqlite3\base.py", line 194, in get_new_connection
    conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file

Bottom line is Git version control is dodgey if not used correctly. Any help is appreciated.

Joelad
  • 492
  • 3
  • 12
  • 1
    Possible duplicate of [Sqlite3, OperationalError: unable to open database file](https://stackoverflow.com/questions/4636970/sqlite3-operationalerror-unable-to-open-database-file) – LinPy Sep 17 '19 at 07:19
  • @LinPy no duplicates and still getting the same error. Also that is to do more with sql and not cmd line – Joelad Sep 17 '19 at 07:22

1 Answers1

1

Make sure to check your database settings (settings.py) to ensure your app is looking in the right location for the database file with the correct name.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

In this example the (database)file named 'db.sqlite3' is placed in the folder that is one level higher than the folder wich contains this/the settings.py file.

Ewald
  • 155
  • 5