0

I am lost with what is probably a very simple issue configuring a django / mysql project. I have a working project on a computer A, which I just want to be able to use with a computer B. On computer A, I have an Eclipse project, using Pydev and Django, a local virtual environnement, and a local database running with Mysql.

What I have done:

  • I exported the virtual environnement (including django) and created the same one on computer B;
  • I used Gitlab in order to get all the files with the code ;
  • I installed Mysql, and created a database with the same name, and a user with the same informations (id / pwd).

The migrations went well, the tables are created like I expected. However, I cannot find a way to run the server. When I try, I get multiple errors saying one (and only one) of the Apps is not loaded yet, then another error, which seems to be related to the database. Here are some of the messages:

Traceback (most recent call last):
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/_pydev_runfiles/pydev_runfiles.py", line 460, in __get_module_from_str
    mod = __import__(modname)
  File "/home/francois/eclipse-workspace/iou/members/forms.py", line 2, in <module>
    from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, UsernameField
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/contrib/auth/forms.py", line 10, in <module>
    from django.contrib.auth.models import User
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/db/models/base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/apps/registry.py", line 136, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
ERROR: Module: members.forms could not be imported (file: /home/francois/eclipse-workspace/iou/members/forms.py).
Traceback (most recent call last):
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/_pydev_runfiles/pydev_runfiles.py", line 460, in __get_module_from_str
    mod = __import__(modname)
  File "/home/francois/eclipse-workspace/iou/members/migrations/0001_initial.py", line 3, in <module>
    import django.contrib.auth.models
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/db/models/base.py", line 108, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/apps/registry.py", line 253, in get_containing_app_config
    self.check_apps_ready()
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/apps/registry.py", line 136, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
ERROR: Module: members.migrations.0001_initial could not be imported (file: /home/francois/eclipse-workspace/iou/members/migrations/0001_initial.py).
done.
Traceback (most recent call last):
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/runfiles.py", line 268, in <module>
    main()
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/runfiles.py", line 95, in main
    return pydev_runfiles.main(configuration)  # Note: still doesn't return a proper value.
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/_pydev_runfiles/pydev_runfiles.py", line 857, in main
    PydevTestRunner(configuration).run_tests()
  File "/home/francois/snap/eclipse/67/amd64/plugins/org.python.pydev.core_10.2.1.202307021217/pysrc/_pydev_runfiles/pydev_runfiles.py", line 780, in run_tests
    get_django_test_suite_runner()(run_tests).run_tests([])
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/test/runner.py", line 723, in run_tests
    databases = self.get_databases(suite)
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/test/runner.py", line 702, in get_databases
    databases = self._get_databases(suite)
  File "/home/francois/anaconda3/envs/iou_env/lib/python3.10/site-packages/django/test/runner.py", line 690, in _get_databases
    for test in suite:
TypeError: 'NoneType' object is not iterable

edit : here is the code for the User model:

from django.db import models
from django.contrib.auth.models import AbstractUser

class Group(models.Model):
    name = models.CharField(max_length=100)
    def __str__(self):
        return self.name   
    
class User(AbstractUser):
    groups = models.ManyToManyField(Group)
    current_group = models.ForeignKey(Group, on_delete=models.SET_NULL,blank = True , null = True, related_name="current_group")

Edit 2 : actually, it seems that most of the errors are related to the imports of the User django class, for example the errors related with forms.py is in line 2, which is this one:

from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, UsernameField

I precise that I have the following line in my settings.py, since I use a personnalized User model, however I tried to delete this line and the issue persists:

AUTH_USER_MODEL = 'members.User'

I really don't understand what is happening here, so I would be gratefull if anyone can help, many thanks!

Francois51
  • 381
  • 2
  • 15
  • You're trying to use an app before it's initialised, or you've got some test that is calling a function that uses some imports from an app. I faced this issue once when I was calling `get_queryset() ` in model forms instead of passing it as a callable. – Ankit Tiwari Aug 06 '23 at 17:01
  • If you provide code related to this error then will be easy to debug it. – Ankit Tiwari Aug 06 '23 at 17:02
  • hi, I can add some code, however it seems weird that this error does not happens on computer A, where the code is the same. Which file should I provide here? – Francois51 Aug 06 '23 at 17:30
  • Does this answer your question? [Suddenly when running tests I get "TypeError: 'NoneType' object is not iterable](https://stackoverflow.com/questions/29855100/suddenly-when-running-tests-i-get-typeerror-nonetype-object-is-not-iterable) – Ankit Tiwari Aug 06 '23 at 19:39
  • It seems error is coming from tests related to **User** – Ankit Tiwari Aug 06 '23 at 19:41
  • I added the User class in my message, but there is the same code on the other computer, and no error. I already looked the link you provided, but 1) I do not have any special test (maybe django runs some tests itself, but I didn't code any test), and 2) the last error makes me think that the problem is database-related (as mentionned in the last answer of the link) – Francois51 Aug 06 '23 at 19:49
  • You've app name `members` which is not loaded. Check this line `ERROR: Module: members.forms could not be imported` this means error is coming from `forms.py` from members app provide `forms.py` content – Ankit Tiwari Aug 06 '23 at 19:57
  • actually, this is multiple errors. One is indeed from the form.py file, however if you look down, you'll see the same errors, but with another file (I don't understand why, it's a migration file). This means to me that it's not a problem related to these files (which again, haven't change since I moved them), but rather an issue with import in general. – Francois51 Aug 06 '23 at 20:25
  • If you can provide your `forms.py ` code, I can check what the issue is. – Ankit Tiwari Aug 07 '23 at 05:38
  • You can create a new virtual environment and install the ```requirements.txt``` file in it. it might resolve the issue. – Muhammad Waqar Anwar Aug 07 '23 at 06:45

1 Answers1

0

So, I don't get why but the issue came from the name of the Eclipse - Pydev project. It seems that I cannot have a project name starting with a low case character (this works perfectly on the other computer thought...). I just renamed the project with an uppercase at the beginning, and it works.

I hope it will help other people, many thanks to those who tried to help!

Francois51
  • 381
  • 2
  • 15