#SystemCheck fails, but only in one enviroment.

68 messages · Page 1 of 1 (latest)

sullen tulip
#

Hello, i have run into a strange problem. We are working on a project and it is a team of multiple people.
As of right now everybody got the same commit, same database, same python version.. same everything.. Even OS. But one of us gets an error:

ERRORS:
auth.User.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'auth.User.groups' clashes with reverse accessor for 'web.User.groups'.
        HINT: Add or change a related_name argument to the definition for 'auth.User.groups' or 'web.User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'auth.User.user_permissions' clashes with reverse accessor for 'web.User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'auth.User.user_permissions' or 'web.User.user_permissions'.
web.User.groups: (fields.E304) Reverse accessor 'Group.user_set' for 'web.User.groups' clashes with reverse accessor for 'auth.User.groups'.
        HINT: Add or change a related_name argument to the definition for 'web.User.groups' or 'auth.User.groups'.
web.User.user_permissions: (fields.E304) Reverse accessor 'Permission.user_set' for 'web.User.user_permissions' clashes with reverse accessor for 'auth.User.user_permissions'.
        HINT: Add or change a related_name argument to the definition for 'web.User.user_permissions' or 'auth.User.user_permissions'.

System check identified 4 issues (0 silenced).

I have no idea why this happends. And it is also hard to debug because it happends only on at device.

#
class User(AbstractUser):
    login_name = models.CharField(unique=True, max_length=45)
    login_passwd = models.CharField(max_length=255)
    email = models.CharField(unique=True, max_length=255)
    locked = models.CharField(max_length=3)
    super = models.CharField(max_length=3)

    class Meta:
        managed = False
        db_table = 'user'

Appears to be closely related to this.. But other members of team can run it with the defined AbstractUser.

dull patrol
#

```py

code here

```

for colors, btw

#

there must be a difference

#

since it complains about auth.User.groups VS web.User.groups maybe your colleague forgot to set settings.AUTH_USER_MODEL to your custom user model as he started? or something similar during setup.

the fact that you User model is marked as managed=False also opens up more issues as Django won't create or modify the associated table through migrations to stay in sync with the model class, so any local offset/difference per developer may be a problem

sullen tulip
#

None of us got that specified. We are still a bit trying to understand the AuthSystem. So that might be the core reason. Just.. Seems weird that we have everything the same on only one of use gets a different error.

dull patrol
#

well it's only logical that something must be different, so don't believe the "everything is the same I swear" too early 😛

#

did you inherit the codebase? it is a bit unusual to have the main custom user model unmanaged

sullen tulip
#

I understand 😄 But git says it is the same and i have manually went through it. But i get it.. There might be something small but different.
We did not inherit the codebase. We are starting from scratch.

dull patrol
#

you may want to do yourself a favor and let Django do its thing with syncing database state to model classes via migrations then, I'd only use managed=False with good reason, which would usually be plugging into an existing database that has been created outside of Django and is also migrated/managed from another system/tool

sullen tulip
#

The managed=False is i belive by default when generating the models via django.

I have only now find out what "managed" really means.. We did inherit the database schema so..

dull patrol
#

nope

#

default is managed

#

so you did inherit the database? or just the schema, what does that mean exactly?

#

ah did you use the inspectdb management command against an existing database by any chance?

sullen tulip
#

we did use inspectdb.

Well our project was supposed to be in plain JS. So we did it the old way. Manualy creating the schema in SQL etc.. Only then we moved to django which has been amazing choice

dull patrol
#

I see. I don't have much experience with that, but you will want to use Django's migration system from here on, so removing the managed=False would be a good idea imho

#

if the database content doesn't matter yet you could also kill it and create it from scratch using Django's models, I guess that would make the most sense

topaz island
sullen tulip
#

I tried using the migrations. But it did nothing since I had the "managed=false" it did nothing

dull patrol
#

well, remove those lines

#

By default, inspectdb creates unmanaged models. That is, managed = False in the model’s Meta class tells Django not to manage each table’s creation, modification, and deletion:

If you do want to allow Django to manage the table’s lifecycle, you’ll need to change the managed option above to True (or remove it because True is its default value).

sullen tulip
#

Yup. I will get it together and look more into auth.

sullen tulip
#

So i have rewrited everything to True. But now when i try to migrate to and completly empty DB i get:

django.db.utils.OperationalError: (1050, "Table 'auth_group' already exists")
django.db.utils.OperationalError: (1050, "Table 'auth_group' already exists")
topaz island
topaz island
#

Whats inside currently?

sullen tulip
#

0001_initial.py

topaz island
#

Can you showme the code?

sullen tulip
#

i think i cant send files

topaz island
#

Open it up, its a py file, copy and send the code in text?

sullen tulip
#

Too long.

topaz island
#

Pastebin?

sullen tulip
#

yzup

topaz island
#

Ok so it looks like in the migration its trying to add the auth tables etc, they are already inside django

sullen tulip
#

Where exactly?

topaz island
#

In your migrations file, You can remove anything related to auth, and migrate, as the django auths will build themselves anyway

#

Looking through you need to keep everything: Activity, Category, DjangoMigrations, DjangoSession, Hashtag, News, Node, User, DjangoContentType, Menu.
Unless you have more custom content

sullen tulip
#

Like remove them manually from the migration file? I am a bit lost

topaz island
#

Yea, if you remove them from the migrations, make sure initial is set to True still

#

Then run migrate again

#

If that doesn't work we can do a fresh migration

sullen tulip
#

I continue to get the same warning but with different tables

#

DjangoSession, Migrations and so on

#

It finished. But i had to delete:
DjangoMigrations,DjangoSession,DjangoContentType and the Auth ones

topaz island
#

Did you get it sorted now?

sullen tulip
#

Oh so if I understand it right the tables I mentioned are created automatically and should not be inside models.py?

topaz island
#

Unless you are making your own system, from what I understand, I am just using basic auth

sullen tulip
#

Well I want to use whats built in but without the web GUI. But either way if I am using the default. It does not belong into models.py?

topaz island
#

Correct if using the default

#

Do you have a "users" app?

sullen tulip
#

Nope

topaz island
sullen tulip
#

Well I want to use different model for the auth user tho..
But that should be somewhere in the docs

topaz island
#

The link I sent talks about customization etc regarding auth

sullen tulip
#

Thanks. I will also go and delete DjangoSession,DjangoMigration and everything related to defaults since it creates in the db automatically and it will only cause problems. Right?

sullen tulip
#

Well seems like it.

topaz island
sullen tulip
#

Probably got into there at some point when using inspectdb

topaz island
#

It most likely happend when you changed the manage flag on django

sullen tulip
#

I cant seem set AUTH_USER_MODEL

#
AUTH_USER_MODEL refers to model 'web.User' that has not been installed```
My APP label is web.. And the model is User
so it should be `web.User` But that
sullen tulip
#

Seems like this problem is here very often. But i cant find a fix.

sullen tulip
#

Might be because AUTH_USER_MODEL is not set. But that does not explain why it works for other collagues