我是Django的新手并创建了我的第一个应用。我创建了一个用户模型,不了解内置的内核。我删除了用户表。
# -*- coding: utf-8 -*- from __future__ import unicode_literals
from django.db import models from django.contrib.auth.models import User
# Create your models here.
# class User(models.Model):
# firstname = models.CharField(max_length=250)
# lastname = models.CharField(max_length=250)
# email = models.CharField(max_length=250)
# password = models.CharField(max_length=250)
# newsletter = models.BooleanField(default=0)
# accountlevel = models.BigIntegerField(default=1)
# reportsCreated = models.BigIntegerField(default=0)
#
# def __str__(self):
# return self.firstname +" "+ self.lastname +" - "+self.email
class Account(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
reports = models.IntegerField(default=3)
accounttype = models.CharField(default='Free')
monthlycost = models.FloatField(default=0.0)
def __str__(self):
return self.user.username + " - " + self.accounttype
admin.py # - - 编码:utf-8 - - 来自 future 导入unicode_literals 来自.models导入用户 来自.models导入报告
from django.contrib import admin
# Register your models here.
admin.site.register(User)
admin.site.register(Report)
我现在需要喜欢来自Account的ForeignKey并将表格报告给内置的用户模型。
我跑的时候:
python manage.py makemigrations
我收到以下错误
django.contrib.admin.sites.AlreadyRegistered:模型用户是 已经注册
答案 0 :(得分:2)
从您应用的admin.py
取消注册该模型。
删除以下行
admin.site.register(User)
然后makemigrations
和migrate
。