当前位置: 首页>>代码示例>>Python>>正文


Python peewee.ProgrammingError方法代码示例

本文整理汇总了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() 
开发者ID:dashpay,项目名称:sentinel,代码行数:22,代码来源:models.py

示例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) 
开发者ID:dashpay,项目名称:sentinel,代码行数:23,代码来源:models.py

示例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 
开发者ID:jaywink,项目名称:social-relay,代码行数:16,代码来源:conftest.py

示例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 
开发者ID:akamai-threat-research,项目名称:mqtt-pwn,代码行数:9,代码来源:database.py

示例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 
开发者ID:mosquito,项目名称:pypi-server,代码行数:9,代码来源:005_packagefile_basename_unique.py

示例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 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:13,代码来源:test.py

示例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') 
开发者ID:keredson,项目名称:peewee-db-evolve,代码行数:12,代码来源:test.py


注:本文中的peewee.ProgrammingError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。