python - Database connection setup broken after updating to Peewee 2.6 from 2.4 -
i want upgrade pewee v2.4.7 v2.6.3 in order use get_or_create method. however, after updating connection setup broken.
i used following superclass enable foreign key contraints sqlite (2.6.3):
class sqlitefkdatabase(sqlitedatabase): def initialize_connection(self): self.execute_sql('pragma foreign_keys=on;') return self
... using following connection setup code:
db = sqlitefkdatabase(none) init_db(path_to_db) def init_db(path_to_db): db.init(path_to_db) db.connect() db.initialize_connection()
however, when run code new version of peewee following error:
file "./script.py", line 40, in init_db db.connect() file "/library/frameworks/python.framework/versions/3.4/lib/python3.4/site-packages/peewee.py", line 3130, in connect self.initialize_connection(self.__local.conn) typeerror: initialize_connection() takes 1 positional argument 2 given
i aware of passing self initialize_connection(), can me find second argument might me, , how fix bug?
edit
changing class declaration method fixes error.
class sqlitefkdatabase(sqlitedatabase): def initialize_connection(self, conn): self.execute_sql('pragma foreign_keys=on;')
initialize_connection
takes parameter, newly-created connection
object.
this should work:
class sqlitefkdatabase(sqlitedatabase): def initialize_connection(self, conn): cursor = conn.cursor() cursor.execute('pragma foreign_keys=on;')
and init_db
not need call initialize_connection
-- handled peewee:
def init_db(path_to_db): db.init(path_to_db) db.connect()
Comments
Post a Comment