Django 'ModuleNotFoundError: No module named 'my_app''

I have been working for some time in a project. One of the apps inside of it, 'my_app' has its models, views, forms, etc. working fine. It is included in INSTALLED_APPS as well.

Now I try to create a new file inside the my_app folder to write some logic but can't import the models. I tried:

from my_app.models import MyModel

But I get this error: ModuleNotFoundError: No module named 'my_app'

Also tried this one as I was doing the imports in, for example, views.py:

from .models import MyModel

But this time I get this error:

ImportError: attempted relative import with no known parent package

These imports are working fine in other files in the same folder. Recently I deployed the app to Railway, maybe that has something to do with this error? Why suddenly this error happened?

EDIT:

my_app/apps.py file:

from django.apps import AppConfig


class My_appConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'my_app'

Also, recently started using Celery and my_project_folder/celery.py looks like this:

from celery import Celery 

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_project.settings')

app = Celery('my_project')
Back to Top