📜  migrations.RunSQL 代码示例

📅  最后修改于: 2022-03-11 15:05:26.982000             🧑  作者: Mango

代码示例1
def set_pg_sequence(apps, schema_editor):
    if connection.vendor == "postgresql":
        # Reset sequence of user so Postgres doesn't crash on an existing user
        # ID 100 for our uploader user.
        # http://stackoverflow.com/a/3698777/85461
        migrations.RunSQL(
            """
            SELECT pg_catalog.setval(
                pg_get_serial_sequence('auth_user', 'id'), MAX(id)
            ) FROM auth_user;
            """.format(table_name=settings.AUTH_USER_MODEL)
        )