Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error creating superuser #389

Closed
rjschave opened this issue May 27, 2020 · 15 comments
Closed

Error creating superuser #389

rjschave opened this issue May 27, 2020 · 15 comments

Comments

@rjschave
Copy link

Cloned copy of repo today (commit 4f0e1ae).

It seems the instructions may need to be updated. Instructions indicate the following:

pip install -r requirements.txt
cp crm/local_settings.example crm/local_settings.py
python manage.py makemigrations
python manage.py createsuperuser
python manage.py runserver

local_settings.example doesn't exist, but _local_settings.py does. I ran the following command

cp crm/_local_settings.py crm/local_settings.py

I think python manage.py makemigrations should be python manage.py migrate

After running migrate command I ran createsuperuser and received an error. The stack track is ~ 70 lines, but here are the relevant bits:

psycopg2.errors.NotNullViolation: null value in column "company_id" violates not-null constraint
django.db.utils.IntegrityError: null value in column "company_id" violates not-null constraint

These errors occur when attempting to insert the user record into the table.

From the User model, it's clear the company field is required, but the createsuperuser does not account for this.

From common/models.py:

class User(AbstractBaseUser, PermissionsMixin):
   ...
   company = models.ForeignKey(Company, on_delete=models.CASCADE)
@liangsqrt
Copy link

I had the same problem

@bdbais
Copy link

bdbais commented Jun 12, 2020

I had same problem too.
I will try to put a default value top model ,default='Ombrella Corp.'

@bdbais
Copy link

bdbais commented Jun 12, 2020

sudo su - postgres

psql

dj_crm=# \d common_company

                                      Table "public.common_company"
   Column   |          Type           | Collation | Nullable |                  Default
------------+-------------------------+-----------+----------+--------------------------------------------
 id         | integer                 |           | not null | nextval('common_company_id_seq'::regclass)
 name       | character varying(100)  |           |          |
 address    | character varying(2000) |           |          |
 sub_domain | character varying(30)   |           | not null |
 user_limit | integer                 |           | not null |
 country    | character varying(3)    |           |          |

INSERT INTO common_company (name,sub_domain,user_limit,country) VALUES ('Ombrella Corp','IT',9999,'USA');

dj_crm=# select * from common_company;

 id |     name      | address | sub_domain | user_limit | country
----+---------------+---------+------------+------------+---------
  2 | Ombrella Corp |         | IT         |       9999 | USA
(1 row)

\q

exit

on file: common/models.py change default of company with id of your company ( in my test id = 2)

class User(AbstractBaseUser, PermissionsMixin):
    file_prepend = "users/profile_pics"
    username = models.CharField(max_length=100, unique=True)
    first_name = models.CharField(max_length=150, blank=True)
    last_name = models.CharField(max_length=150, blank=True)
    email = models.EmailField(max_length=255, unique=True)
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    date_joined = models.DateTimeField(("date joined"), auto_now_add=True)
    role = models.CharField(max_length=50, choices=ROLES)
    profile_pic = models.FileField(
        max_length=1000, upload_to=img_url, null=True, blank=True
    )
    has_sales_access = models.BooleanField(default=False)
    has_marketing_access = models.BooleanField(default=False)
    company = models.ForeignKey(Company, on_delete=models.CASCADE,default=2)

save file and do :

python manage.py makemigrations

Migrations for 'common':
  common/migrations/0022_auto_20200612_1404.py
    - Alter field company on user

python manage.py migrate

Operations to perform:
  Apply all migrations: accounts, auth, cases, common, contacts, contenttypes, emails, events, invoices, leads, marketing, opportunity, planner, sessions, tasks, teams, thumbnail
Running migrations:
  Applying common.0022_auto_20200612_1404... OK

python manage.py createsuperuser

Email: dr.oswell@ombrellacorp.com
Username: crm
Password:
Password (again):
Superuser created successfully.

@bdbais
Copy link

bdbais commented Jun 12, 2020

python manage.py runserver 0.0.0.0:9000

http://127.0.0.1:9000/login

I have this error on login:

500
The page you're looking for could not be found.
Make sure the address is correct and that the page hasn't moved.

Please contact your administrator if you think this is a mistake.

GO back Home CRM Home
There may be an issue related to System Requirements,

install these packages to resolve them.

Home page show:

bottlecrm
Coming soon ...

probably is not ready to work?

@bdbais
Copy link

bdbais commented Jun 12, 2020

python manage.py collectstatic

    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

but on crm/settings.py

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

STORAGE_TYPE = os.getenv("STORAGE_TYPE", "normal")

if STORAGE_TYPE == "normal":
    MEDIA_ROOT = os.path.join(BASE_DIR, "media")
    MEDIA_URL = "/media/"

    STATIC_URL = "/static/"
    STATICFILES_DIRS = (BASE_DIR + "/static",)
    COMPRESS_ROOT = BASE_DIR + "/static/"

...

STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "compressor.finders.CompressorFinder",
)

and directory exist:

drwxrwxr-x 7 crm crm 4096 Jun 12 08:44 static

but probably STATIC_ROOT env is not present so I will add it on settings:

STATIC_ROOT = os.path.join(BASE_DIR,'static')

now collectstatic has no errors, and no files found...

python manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /home/crm/Django-CRM/static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

0 static files copied to '/home/crm/Django-CRM/static', 21 unmodified.

but.... at runserver

 SystemCheckError: System check identified some issues:

ERRORS:
?: (staticfiles.E002) The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting.
****

@shaikhmasud147
Copy link

shaikhmasud147 commented Jun 20, 2020

Same issue facing me. @bdbais get you any solution for this?

@ashwin31
Copy link
Member

This is going to be SaaS. So, no need of super user.

@shaikhmasud147
Copy link

@ashwin31 Ok. Please let me know how can i login with subdomain? What is exact process so i can login. Please help me for this. thanks

@ashwin31
Copy link
Member

Add the subdomain to your host config file. /etc/hosts

@shaikhmasud147
Copy link

shaikhmasud147 commented Jun 21, 2020

@ashwin31 Company does not exist. Please let me know how can i create new company. Please check the screenshot. I have get git repository on my local system. I have also create domain /etc/hosts (django-crm.com).

https://ibb.co/yXNsbcp

I am tring to register new company but get the error. Please check the link
https://ibb.co/nbYNNGH

@nevros
Copy link

nevros commented Aug 5, 2020

Seems there has been some changes to the code but this issue still remains. The migration does not create the default Company anymore so I was able to add this into the database directly and update the user to be a part of this company.

Point to note is that the Company sub_domain should be 'tenant1.localhost' and the name 'tenant1'

Getting started with this project is not the easiest.

@ashwin31
Copy link
Member

ashwin31 commented Aug 5, 2020

@rjschave @liangsqrt @bdbais @shaikhmasud147 @nevros check readme.md I made it easy to setup and configure in local machines. Let me know if you find any further difficulties.

@ashwin31 ashwin31 reopened this Aug 5, 2020
@ashwin31 ashwin31 closed this as completed Aug 5, 2020
@ashwin31
Copy link
Member

ashwin31 commented Aug 5, 2020

@nevros you don't need to add company or user to database. You can register new company and user from the UI.

@nevros
Copy link

nevros commented Aug 5, 2020

How does one do that? I was following the readme and it does not provide much information on how to sign in.

@ashwin31
Copy link
Member

ashwin31 commented Aug 5, 2020

Ok, Today, I will do a video and add to readme.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants