示例#1
0
def test_drop_fk():
    ret = Migrate.ddl.drop_fk(
        Category,
        Category._meta.fields_map.get("user").describe(False),
        User.describe(False))
    if isinstance(Migrate.ddl, MysqlDDL):
        assert ret == "ALTER TABLE `category` DROP FOREIGN KEY `fk_category_user_e2e3874c`"
    elif isinstance(Migrate.ddl, PostgresDDL):
        assert ret == 'ALTER TABLE "category" DROP CONSTRAINT "fk_category_user_e2e3874c"'
    else:
        assert ret == 'ALTER TABLE "category" DROP FOREIGN KEY "fk_category_user_e2e3874c"'
示例#2
0
def test_add_fk():
    ret = Migrate.ddl.add_fk(
        Category,
        Category._meta.fields_map.get("user").describe(False),
        User.describe(False))
    if isinstance(Migrate.ddl, MysqlDDL):
        assert (
            ret ==
            "ALTER TABLE `category` ADD CONSTRAINT `fk_category_user_e2e3874c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE"
        )
    else:
        assert (
            ret ==
            'ALTER TABLE "category" ADD CONSTRAINT "fk_category_user_e2e3874c" FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE'
        )