-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
On Sun, Jan 13, 2019 at 11:49:44PM -0800, ANi wrote:
> Hello.
>
> I want to migrate all tables into new database but bumped into an error
> that it said "auth_permission" is not found.
> Then I searched for the possible causes, it turned out that it is because I
> accessed the auth model "Permission" in my code before the migrate creating
> table in database.
> I tried to run *python manage.py migrate auth, *but nothing changed.
>
> So maybe I have to change my code ... I have to filter out managers by its
> permission.
>
> manager_permission = Permission.objects.get(codename='manager')
> managers = User.objects.filter(project=project).filter(user_permissions=
> manager_permission)
>
> User.user_permissions is only allowed to use the permission code which
> could be different every time I re-migrate the whole database.
>
> So I am asking if there is a better way to filter out managers by its perm
> or other solutions ? :)
Hi,
The problem is that you're not supposed to execute any database
queries when your application is getting imported – you should only do
that at runtime, when everything has been initialized, and when you're
handling a request (or a management command, or a background job, such
as celery, or whatnot).
It's a bit difficult to go into more detail, because you haven't
provided a whole lot of information, but those queries that you're
executing in module scope should go into functions and methods that
you only call when you actually need that data. It would be easier to
give you more specific advice if you posted the relevant parts of your
code, though.
Good luck,
Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQIcBAEBCgAGBQJcPMMcAAoJEHA7T/IPM/klYBEQAIq+exMdhBSLR7Vskpzavd2p
HHLIZYl9DuVOaxtW5sg0qIu92rLVGf8taPLzhIZJA5LHGlnYaFPMo0Bs6eNCdUnr
Bpxzt1xzJFiqou96NFFveG1N1ywCfAvPNqNhyTRJjX0iRv3n2LFk5XQ05V3GUcvv
V/+wvTm6ZlffVHuCWKIWypkY2yMZhFryTebmZOmavptNVMx5FpU4FcEBLufE5qvw
j0BmnvXRqUkuEhtyqGNcnjl496khb5Zu9zKfZcrjyDDvTlhC0nS4hS5MDZxkih6x
RfX2p0vjOctJhnKiywBIjOGNR5jFEYGCqVkyYds0rF6kNSvLRelxgJtB8Ms8yIkE
VffEsuVlS56DTtxIyyhJcnwYVA0JqO4QvEDY4VB6N7Is+Kd/dGrk0+qdhd4psawb
pNYhwWNMjvvl6aCpvPd+5rKFUW7I25mD2F+tx7/5EcVCp7767NG0nnMiSTqXnz5w
4aU09pzM7TCwr+2rTvdsM94jui/0bfWA437sLcpyQ+uALwzqc89i3vN4aVrnJRDv
W2Y1TJxS2v1uyqwvTYmx+7vNFT7lsDfFKKabwGvcMP7YdbwFCYNIvQKj229N3Y53
Fn25XOJe/WdfNAtzJP/m7UBuyaVorBZWVpFR4QHG+LTLRieEySmhgVe5seu9G50i
XCW0pAY72G3Kblzb4ZWI
=Nwlv
-----END PGP SIGNATURE-----