bulk_update() causes Select N+1 issue

2023-01-13 Thread Nick Chang
Hi all,

I read django doc on 'bulk_update() 
'  
It said that generally it creates one single query to do so, but in a 
project I have has 'a_model.objects.bulk_update(update_list, 
fields=updated_keys), it actually generates N number of SELECT statements 
where N is the size of 'update_list'  This is being flagged as Select N+1 
bug.

Why did bulk_update() not generate a single query as it advertises? How 
would I fix this Select N+1 issue to increase the performance?

Kind Regards,

Nick

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc688786-e8db-4071-b1d3-13b2a17436bbn%40googlegroups.com.


Re: Move apps to different folders or to a root folder

2022-11-10 Thread Nick Chang
Hi Mike,

Thanks for your reply. To further clarify about `db_table` name regarding 
this vertical move. The 'db_table' field is actually already specified in 
the models. However, if the 'db_table' name were not specified in the model 
and let django handle generation table names, would this move break it?  
And it can be fixed by specifying the 'db_table" value in the moved models?

Thanks!

On Sunday, November 6, 2022 at 10:09:41 PM UTC-5 Mike Dewhirst wrote:

> On 7/11/2022 2:40 am, Nick Chang wrote:
>
> Hello community, 
>
> I am trying to organize my Django project's structure as the number of 
> apps is growing. So I am attempting to move an app in the sub-folder that 
> contains its model definitions. The app used to be named `<
> sub_folder_name>.foo <http://sub_folder_name%3E.foo/>` and now it will be 
> just named `foo` in the `LOCAL_APPS` setting.
>
> It seems straightforward to do this with the following two steps:
>
>1. Change the reference from `.foo 
><http://sub_folder_name%3E.foo/>` to `foo` in the whole project. 
>2. Do `mv foo ..` inside the sub-folder. 
>
> Is there any DB migration work that this move requires? Or since the app 
> name stays the same. There is nothing that needs to be done as Django does 
> not see any change in the models. So far my investigation confirms no DB 
> migration work is needed but would like to hear some experiences that folks 
> might have done before.
>
>
> Should work just fine.
>
> In any case, you can also specify the table name the model should use if 
> you do decide to switch models between apps ...
>
> class Meta:
>  app_label = "company"
>  db_table = "common_user"
>
> If your python code works and your tests pass everything should be 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...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5ac5eea7-f620-4d11-9796-3439231939f3n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/5ac5eea7-f620-4d11-9796-3439231939f3n%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>
>
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9f355cfa-12ed-4e4b-86a5-7c5ee4c348c3n%40googlegroups.com.


Move apps to different folders or to a root folder

2022-11-06 Thread Nick Chang
Hello community,

I am trying to organize my Django project's structure as the number of apps 
is growing. So I am attempting to move an app in the sub-folder that 
contains its model definitions. The app used to be named `<
sub_folder_name>.foo ` and now it will be 
just named `foo` in the `LOCAL_APPS` setting.

It seems straightforward to do this with the following two steps:

   1. Change the reference from `.foo 
   ` to `foo` in the whole project.
   2. Do `mv foo ..` inside the sub-folder.

Is there any DB migration work that this move requires? Or since the app 
name stays the same. There is nothing that needs to be done as Django does 
not see any change in the models. So far my investigation confirms no DB 
migration work is needed but would like to hear some experiences that folks 
might have done before.

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5ac5eea7-f620-4d11-9796-3439231939f3n%40googlegroups.com.