Created
March 14, 2017 15:32
-
-
Save iref/49fefe5766380c4c68154cdb15236fd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3688, in _create_connection | |
return self._connect(self.database, **self.connect_kwargs) | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3939, in _connect | |
conn = sqlite3.connect(database, **kwargs) | |
sqlite3.OperationalError: unable to open database file | |
During handling of the above exception, another exception occurred: | |
Traceback (most recent call last): | |
File "example.py", line 45, in <module> | |
main() | |
File "example.py", line 41, in main | |
create_schema() | |
File "example.py", line 20, in create_schema | |
db.connect() | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3660, in connect | |
self._local.conn = self._create_connection() | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3688, in _create_connection | |
return self._connect(self.database, **self.connect_kwargs) | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3578, in __exit__ | |
reraise(new_type, new_type(*exc_args), traceback) | |
File "./env/lib/python3.5/site-packages/peewee.py", line 135, in reraise | |
raise value.with_traceback(tb) | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3688, in _create_connection | |
return self._connect(self.database, **self.connect_kwargs) | |
File "./env/lib/python3.5/site-packages/peewee.py", line 3939, in _connect | |
conn = sqlite3.connect(database, **kwargs) | |
peewee.OperationalError: unable to open database file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import peewee | |
import sqlite3 | |
dirname = os.path.dirname(__file__) | |
db_file = os.path.abspath( | |
os.path.join(dirname, 'mydb.db') | |
) | |
db = peewee.SqliteDatabase('sqlite://' + db_file) | |
class Entry(peewee.Model): | |
title = peewee.TextField() | |
text = peewee.TextField() | |
def peewee_create_schema(): | |
db.connect() | |
db.create_tables([Entry]) | |
def connect_db(): | |
rv = sqlite3.connect(db_file) | |
rv.row_factory = sqlite3.Row | |
return rv | |
def sqlite3_create_db(): | |
rv = connect_db() | |
with open('schema.sql', 'r') as f: | |
rv.cursor().executescript(f.read()) | |
def main(): | |
# This works | |
sqlite3_create_db() | |
# This does not | |
peewee_create_schema() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment