# Need help about django query--one model with many tables

**URL:** <https://forum.djangoproject.com/t/need-help-about-django-query-one-model-with-many-tables/11406>\
**Category:** Using Django\
**Created:** [January 6, 2022, 9:15am UTC](https://forum.djangoproject.com/t/need-help-about-django-query-one-model-with-many-tables/11406 "2022-01-06T09:15:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanyf1983](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hanyf1983/32/6952_2.png) [@hanyf1983](https://forum.djangoproject.com/u/hanyf1983)\
**Post date:** [January 6, 2022, 9:15am UTC](https://forum.djangoproject.com/t/need-help-about-django-query-one-model-with-many-tables/11406/1 "2022-01-06T09:15:19Z")

</div>

i have to create lots of tables shared one model.  
Model like this:

```auto
class MDR_Design(models.Model):
    col_file_no=models.CharField(max_length=30,primary_key=True)
    col_file_name=models.CharField(max_length=100)   
   ...

```

then , create table with pymysql connection

```auto
....
cur.execute("create table " + projCode + " select * from appname_mdr_design where 1=2")
.....

```

then ,i have tables: table001,table002,…

in the views:

```auto

   MDR_Design._meta.db_table=table001
   items=MDR_Design.objects.filter(..)....
   ....
   MDR_Design._meta.db_table=table002
   items=MDR_Design.objects.filter(..)....

```

and at this time ,error raised like this:

`**(1054, "Unknown column 'table001.col_file_no' in 'field list'")**`

how to handle this problem, thank you very very much

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 6, 2022, 1:26pm UTC](https://forum.djangoproject.com/t/need-help-about-django-query-one-model-with-many-tables/11406/2 "2022-01-06T13:26:54Z")

</div>

You’re not really clear here on what all you’re really trying to achieve by this. My initial reaction to what you have posted is that it appears to me you’re trying to copy a pattern you’ve seen or used in a different application, to Django - when it may not be appropriate to do so directly.

But aside from that, Django expects the tables to exist when it starts. Django is not designed to provide for creating tables while it’s up and running. Django expects you to have your models defined first. Then, you can use `makemigrations` and `migrate` to create the tables before starting the web service.

But in general, you can create multiple models from a [single abstract model](https://docs.djangoproject.com/en/4.0/topics/db/models/#abstract-base-classes). You could create your `MDR_Design` model as an abstract class and then create your subclasses from it.
