shourav
shourav

Reputation: 996

Dynamic table and model generate in django

I want to create some database tables and models.Model on api call in django. I created on demand Model model = type(str(project_slug + "_tbl_name"), (models.Model,), attrs) and I want to create table like this db.create_table(table_name, fields) create_table was from south but south is not available in Django 1.11 what I am using

How can I generate Model and database tables programmatically?

Upvotes: 1

Views: 2679

Answers (1)

shourav
shourav

Reputation: 996

https://docs.djangoproject.com/en/1.11/ref/schema-editor/#create-model

example:

with connection.schema_editor() as schema_editor:
   schema_editor.create_model(my_model)

Upvotes: 3

Related Questions