How to create table during Django tests with managed = False

前端 未结 9 1866
执笔经年
执笔经年 2020-12-24 12:25

I have a model with managed = False.

class SampleModel(models.Model):
    apple = models.CharField(max_length=30)
    orange = models.CharField(max_length=3         


        
9条回答
  •  既然无缘
    2020-12-24 12:47

    Execute raw SQL to create the table in the test setup:

    from django.db import connection
    
    class MyTest(unittest.TestCase):
        def setUp(self):
            connection.cursor().execute("CREATE TABLE ...")
    
        def tearDown(self):
            connection.cursor().execute("DROP TABLE ...")
    

提交回复
热议问题