Thanks for the answer.
What do you suggest to use instead of this ugly method, raw sql?

суббота, 14 ноября 2015 г., 17:59:51 UTC+3 пользователь Tim Graham написал:
>
> I'm not sure that type of monkeypatching of Model._meta.db_table is meant 
> to be supported. You could try to bisect Django's commit history to find 
> the commit that changed the behavior. My guess it that it might have to do 
> with some internal caching such that your monkeypatch no longer has any 
> effect.
>
> On Friday, November 13, 2015 at 1:40:21 PM UTC-5, [email protected] 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_project_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_create(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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f30cb65d-e76d-4829-924c-368e5177aff1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to