I don't think that sould be possible to change real table name "on the
fly". If I'm not mistaken, that kind of attribute is used by model's meta
class during class creation process to populate the django model cache,
which in turn only occurs during the django configuration step.

2017-07-13 14:08 GMT-03:00 Kalvin Handilist <khandil...@gmail.com>:

> Hi I encounter same problem as your, do you already got the solution? Any
> help will be appreciated, thank you~
>
> On Saturday, November 14, 2015 at 1:40:21 AM UTC+7, evil...@gmail.com
> wrote:
>>
>> Hello.
>> I've got the same model in two projects and want to copy data from one to
>> another using model meta 'db_table' option:
>>
>>
>> my_model_original_table_name = MyModel._meta.db_table
>> MyModel._meta.db_table = 'old_project_table_name'
>>
>> old_objects = MyModel.objects.using('old_pro
>> ject_data_base').values('name')
>> old_objects = list(old_objects)
>>
>> MyModel._meta.db_table = my_model_original_table_name
>>
>> for old_object in old_objects:
>>     new_object, created = MyModel.objects.update_or_crea
>> te(name=old_object['name'])
>>
>>
>> Old data retrieving works great, but when i try to execute last statement
>> i get:
>> "django.db.utils.ProgrammingError: missing FROM-clause entry for table
>> "old_project_table_name""
>>
>> I tied to fetch data at the last stage instead of updating/creating
>> (MyModel.objects.all()) and get the same error.
>> The sql-query created by ORM is:
>> SELECT "old_project_table_name"."name" FROM "new_project_table_name"
>>
>> Why is it so?
>>
>> I am using django 1.8.6 and PostgreSQL 9.4.5
>> Django 1.7.* work fine.
>>
>>
>> Thanks!
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/django-users/0b3e71a1-ac34-459b-a2b0-32086492077d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0b3e71a1-ac34-459b-a2b0-32086492077d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOs3Lp6-30AfypgUbFhC%2Bhtq6i9p7dXQBiKgS_ih4%2Bij8D9Kug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to