Reputation: 1
I am learning Django 3 but having a problem. My app is called calc1. Code below:
MODELS.PY
from django.db import models
# Create your models here.
class Dreamreal(models.Model):
website = models.CharField(max_length = 50)
mail = models.CharField(max_length = 50)
name = models.CharField(max_length = 50)
phonenumber = models.IntegerField()
class Meta:
db_table = "dreamreal"
VIEWS.PY
from django.shortcuts import render
from django.http import HttpResponse
import datetime
import time
from .models import Dreamreal
from django.http import HttpResponse
# Create your views here.
def home(request):
today = datetime.datetime.now().date()
return render(request, 'home.html',{'today' :today})
def crudops(request):
dreamreal = Dreamreal(
website = "www.vlcbt.org.uk", mail = "[email protected]",
name = "John", phonenumber = "08767655665"
)
dreamreal.save()
# read all entries and print
objects = Dreamreal.objects.all()
res ="printing all documents <br>"
for elt in objects:
res += elt.name +"<br>"
return HttpResponse(res)
When I try to migrate I get the following error message:
File "C:\Users\john\Envs\lms\Scripts\projects\jkjlms\calc1\urls.py", line 3, in from . import views File "C:\Users\john\Envs\lms\Scripts\projects\jkjlms\calc1\views.py", line 5, in from .models import Dreamreal File "C:\Users\john\Envs\lms\Scripts\projects\jkjlms\calc1\models.py", line 5, in class Dreamreal(models.Model): File "C:\python\lib\site-packages\django\db\models\base.py", line 115, in new "INSTALLED_APPS." % (module, name) RuntimeError: Model class calc1.models.Dreamreal doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Thanks for your help in advance
Upvotes: 0
Views: 1142
Reputation: 63
Just add Django's Sites framework to your apps and set SITE_ID
to 1 in your settings.
INSTALLED_APPS = [
...
'django.contrib.sites',
]
SITE_ID = 1
Upvotes: 0
Reputation: 330
You should add your app in settings.py file in INSTALLED_APPS:
INSTALLED_APPS = [
# ...,
calc1,
]
Also, before migration you should do python manage.py makemigrations calc1
Upvotes: 3