shourav shourav - 3 years ago 219
MySQL Question

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?

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download