python alter 表名_Python migrations.AlterModelTable方法代码示例

# 需要导入模块: from django.db import migrations [as 别名]

# 或者: from django.db.migrations import AlterModelTable [as 别名]

def test_alter_model_table(self):

"""

Tests the AlterModelTable operation.

"""

project_state = self.set_up_test_model("test_almota")

# Test the state alteration

operation = migrations.AlterModelTable("Pony", "test_almota_pony_2")

self.assertEqual(operation.describe(), "Rename table for Pony to test_almota_pony_2")

new_state = project_state.clone()

operation.state_forwards("test_almota", new_state)

self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony_2")

# Test the database alteration

self.assertTableExists("test_almota_pony")

self.assertTableNotExists("test_almota_pony_2")

with connection.schema_editor() as editor:

operation.database_forwards("test_almota", editor, project_state, new_state)

self.assertTableNotExists("test_almota_pony")

self.assertTableExists("test_almota_pony_2")

# And test reversal

with connection.schema_editor() as editor:

operation.database_backwards("test_almota", editor, new_state, project_state)

self.assertTableExists("test_almota_pony")

self.assertTableNotExists("test_almota_pony_2")

# And deconstruction

definition = operation.deconstruct()

self.assertEqual(definition[0], "AlterModelTable")

self.assertEqual(definition[1], [])

self.assertEqual(definition[2], {'name': "Pony", 'table': "test_almota_pony_2"})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值