本文整理汇总了Python中peewee.ProgrammingError方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.ProgrammingError方法的具体用法?Python peewee.ProgrammingError怎么用?Python peewee.ProgrammingError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.ProgrammingError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_db_sane
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def check_db_sane():
""" Ensure DB tables exist, create them if they don't. """
check_db_schema_version()
missing_table_models = []
for model in db_models():
if not getattr(model, 'table_exists')():
missing_table_models.append(model)
printdbg("[warning]: Table for %s (%s) doesn't exist in DB." % (model, model._meta.db_table))
if missing_table_models:
printdbg("[warning]: Missing database tables. Auto-creating tables.")
try:
db.create_tables(missing_table_models, safe=True)
except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
print("[error] Could not create tables: %s" % e)
update_schema_version()
purge_invalid_amounts()
示例2: check_db_schema_version
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def check_db_schema_version():
""" Ensure DB schema is correct version. Drop tables if not. """
db_schema_version = None
try:
db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
printdbg("[info]: Can't get DB_SCHEMA_VERSION...")
printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
if (SCHEMA_VERSION != db_schema_version):
printdbg("[info]: Schema version mis-match. Syncing tables.")
try:
existing_table_names = db.get_tables()
existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
if (existing_models):
printdbg("[info]: Dropping tables...")
db.drop_tables(existing_models, safe=False, cascade=False)
except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
print("[error] Could not drop tables: %s" % e)
示例3: app
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def app(request):
from social_relay import app, database
try:
drop_all_tables(database)
except (ProgrammingError, OperationalError):
pass
create_all_tables(database)
def drop_db():
drop_all_tables(database)
request.addfinalizer(drop_db)
return app
示例4: create_tables
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def create_tables(db, tables):
""" Creates the given tables """
try:
db.create_tables(tables)
except ProgrammingError:
pass
示例5: add_uniquie_basename_index
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def add_uniquie_basename_index(migrator, db):
try:
migrate(
migrator.add_index('packagefile', ('basename',), True)
)
except (OperationalError, ProgrammingError):
pass
示例6: test_drop_table
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def test_drop_table(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
self.evolve_and_check_noop()
SomeModel.create(some_field='woot')
peeweedbevolve.clear()
self.evolve_and_check_noop()
with self.assertRaises(pw.ProgrammingError):
SomeModel.create(some_field='woot2') # fails because table isn't there
示例7: test_ignore_new_model
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import ProgrammingError [as 别名]
def test_ignore_new_model(self):
class SomeModel(pw.Model):
some_field = pw.CharField(null=True)
class Meta:
database = self.db
evolve = False
self.evolve_and_check_noop()
with self.assertRaises(pw.ProgrammingError):
# should fail because table does not exist
SomeModel.create(some_field='woot')