python - Django + Django-Rest framework cannot add M2M relation between objects -
i developing rest api drf , have issue when try add m2m relation between existing objects in db error:
raise appregistrynotready("models aren't loaded yet.") django.core.exceptions.appregistrynotready: models aren't loaded yet. everything works fine when try same thing console. problem occurs when execute method:
@staticmethod def update_sockets(): c1 = apicountry.objects.all()[3] s1 = sockettype.objects.all()[2] c1.sockettype.add(s1) c1.save() models are:
class sockettype(models.model): name = models.charfield(max_length=1, blank=true) country = models.manytomanyfield(apicountry, blank=true, related_name='sockettype') class apicountry(models.model): countrycode = models.charfield(max_length=5, unique=true, blank=true) name = models.charfield(max_length=50, blank=true)
i had similar issue. try add these lines @ beginning of program
import django
django.setup()
Comments
Post a Comment