Brais Gabin Brais Gabin - 1 year ago 129
Python Question

How to create table during Django tests with managed = False?

From the oficial documentation:

For tests involving models with
, it’s up to you to ensure the correct tables are created as part of the test setup.

I don't know how to create the tables as part of the test setup. I found this question and the accepted answer doesn't work for me. I think this is because the migrations files. The configuration is in the migrations files, to change the values "on the fly" don't have any effect.

What's the way to solve this in Django 1.7+?

Answer Source

I found a way. Modify the fixtures and add the SQL to generate the tables: (or followings)
class Migration(migrations.Migration):

    operations = [
        migrations.RunSQL("CREATE TABLE..."),

I'm a "migrations newbie" so I don't know if this is the best option. But it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download