Peteros527
Peteros527

Reputation: 5

ModuleNotFoundError, even thought it exist, and is installed

I tried makemigrations and i get:

from SocialNetwork.Accounts.models import User ModuleNotFoundError: No module named 'SocialNetwork.Accounts''=

I made a few applications, installed it in settings, and even pycharm sees it, but I get the error shown above.

This is my project structure:

-SocialNetwork (main directory)
  -SocialNetwork (project package)
      -Accounts
       -__init__.py
       -admin.py
       -apps.py
       -models.py
       -tests.py
       -urls.py
       -views.py
     -Chats
       -__init__.py
       -admin.py
       -apps.py
       -models.py
       -tests.py
       -urls.py
       -views.py
     -Other apps
     -SocialNetwork (settings, wsgi, urls etc)

And tried install models from account in chats:

from django.db import models

from SocialNetwork.Accounts.models import User


class Chat(models.Model):

    firstUser = models.ForeignKey(User, on_delete=models.CASCADE)
    secondUser = models.ForeignKey(User, on_delete=models.CASCADE)

I doubt that it will be helpful but i can write models from user:

class User(models.Model):

    name = models.CharField(max_length=50, null=True)
    phone = models.PhoneNumberField()
    dateBirth = models.DateField(blank=True, null=True)
    description = models.CharField(max_length=200, blank=True, null=True

I have been sitting with this for 2 hours, what can I do in this case? Maybe something more with settings or structure? But structure seems be as always in django projects. Any help will be appreciated, I am new in django.

Upvotes: 0

Views: 73

Answers (2)

gdef_
gdef_

Reputation: 1936

Add an empty __init__.py to your SocialNetwork folder so it can be recognized as a package. Check the docs.

And do from Accounts.models import User instead.

Upvotes: 2

prashant sachdeva
prashant sachdeva

Reputation: 74

You can use:

from Accounts.models import User

Upvotes: 0

Related Questions