Привет я использую следующие модели для создания базы данных
from django.db import models
from django.contrib import admin
class Team(models.Model):
"""Model docstring"""
slug = models.SlugField(max_length=200)
Team_ID = models.AutoField(primary_key=True)
Team_Name = models.CharField(max_length=100,)
College = models.CharField(max_length=100,)
College = models.CharField(max_length=1,)
Win = models.IntegerField()
Loss = models.IntegerField()
Draw = models.IntegerField()
class Match(models.Model):
Match_Id = models.AutoField(primary_key=True)
Team_one = models.ManyToManyField('Team',related_name='Team one',symmetrical=False,)
Team_two = models.ManyToManyField('Team',related_name='Team two',symmetrical=False,)
stadium = models.CharField(max_length=255, blank=True)
Start_time = models.DateTimeField(auto_now_add=False, auto_now=False, blank=True, null=True)
Rafree = models.CharField(max_length=255, blank=True)
Judge = models.CharField(max_length=255, blank=True)
winner = models.ForeignKey('Team', related_name='winner',to_field='Team_Name')
updated = models.DateTimeField('update date', auto_now=True )
created = models.DateTimeField('creation date', auto_now_add=True )
когда я запускаю файл manage.py sqlall, модель корректно проверяется и выдает вывод sql следующим образом
BEGIN;
CREATE TABLE "cupmanager_player" (
"slug" varchar(200) NOT NULL,
"Player_Id" serial NOT NULL PRIMARY KEY,
"Player_Name" varchar(100) NOT NULL,
"Nick" varchar(100) NOT NULL,
"Jersy_Number" integer NOT NULL,
"Team_id_id" integer NOT NULL,
"Poistion" varchar(1) NOT NULL,
"Red_card" integer NOT NULL,
"Yellow_card" integer NOT NULL,
"Points" integer NOT NULL
)
;
CREATE TABLE "cupmanager_team" (
"slug" varchar(200) NOT NULL,
"Team_ID" serial NOT NULL PRIMARY KEY,
"Team_Name" varchar(100) NOT NULL,
"College" varchar(1) NOT NULL,
"Win" integer NOT NULL,
"Loss" integer NOT NULL,
"Draw" integer NOT NULL
)
;
ALTER TABLE "cupmanager_player" ADD CONSTRAINT "Team_id_id_refs_Team_ID_1a532b57" FOREIGN KEY ("Team_id_id") REFERENCES "cupmanager_team" ("Team_ID") DEFERRABLE INITIALLY DEFERRED;
CREATE TABLE "cupmanager_match" (
"Match_Id" serial NOT NULL PRIMARY KEY,
"stadium" varchar(255) NOT NULL,
"Start_time" timestamp with time zone,
"Rafree" varchar(255) NOT NULL,
"Judge" varchar(255) NOT NULL,
"winner_id" varchar(100) NOT NULL REFERENCES "cupmanager_team" ("Team_Name") DEFERRABLE INITIALLY DEFERRED,
"updated" timestamp with time zone NOT NULL,
"created" timestamp with time zone NOT NULL
)
;
CREATE TABLE "cupmanager_goal" (
"Goal_ID" serial NOT NULL PRIMARY KEY,
"Match_ID_id" integer NOT NULL REFERENCES "cupmanager_match" ("Match_Id") DEFERRABLE INITIALLY DEFERRED,
"Team_ID_id" varchar(100) NOT NULL REFERENCES "cupmanager_team" ("Team_Name") DEFERRABLE INITIALLY DEFERRED,
"Player_ID_id" varchar(100) NOT NULL REFERENCES "cupmanager_player" ("Player_Name") DEFERRABLE INITIALLY DEFERRED,
"name" varchar(100) NOT NULL,
"updated" timestamp with time zone NOT NULL,
"created" timestamp with time zone NOT NULL
)
;
CREATE TABLE "cupmanager_match_Team_one" (
"id" serial NOT NULL PRIMARY KEY,
"match_id" integer NOT NULL REFERENCES "cupmanager_match" ("Match_Id") DEFERRABLE INITIALLY DEFERRED,
"team_id" integer NOT NULL REFERENCES "cupmanager_team" ("Team_ID") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("match_id", "team_id")
)
;
CREATE TABLE "cupmanager_match_Team_two" (
"id" serial NOT NULL PRIMARY KEY,
"match_id" integer NOT NULL REFERENCES "cupmanager_match" ("Match_Id") DEFERRABLE INITIALLY DEFERRED,
"team_id" integer NOT NULL REFERENCES "cupmanager_team" ("Team_ID") DEFERRABLE INITIALLY DEFERRED,
UNIQUE ("match_id", "team_id")
)
;
CREATE INDEX "cupmanager_player_slug" ON "cupmanager_player" ("slug");
CREATE INDEX "cupmanager_player_Team_id_id" ON "cupmanager_player" ("Team_id_id");
CREATE INDEX "cupmanager_team_slug" ON "cupmanager_team" ("slug");
CREATE INDEX "cupmanager_match_winner_id" ON "cupmanager_match" ("winner_id");
CREATE INDEX "cupmanager_goal_Match_ID_id" ON "cupmanager_goal" ("Match_ID_id");
CREATE INDEX "cupmanager_goal_Team_ID_id" ON "cupmanager_goal" ("Team_ID_id");
CREATE INDEX "cupmanager_goal_Player_ID_id" ON "cupmanager_goal" ("Player_ID_id");
COMMIT;
но теперь, когда я запускаю команду manage.py syncdb, я получаю следующую ошибку
psycopg2.ProgrammingError: there is no unique constraint matching given keys for referenced table "cupmanager_team"
Есть идеи, что здесь происходит? я использую postgresql в качестве базы данных db и Postgresql_psycopg2
в качестве базы данных db