Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:54:46+00:00 2026-05-13T19:54:46+00:00

hi i am using the following models to build a database from django.db import

  • 0

hi i am using the following models to build a database

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 )

when i run the manage.py sqlall the model validate fine and gives me the sql output as follows

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;

but when i now run the manage.py syncdb command i get the following error
psycopg2.ProgrammingError: there is no unique constraint matching given keys for referenced table "cupmanager_team"

any idea what is going on here ? i am using postgresql as the db backend and Postgresql_psycopg2 as the db back end

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:54:46+00:00Added an answer on May 13, 2026 at 7:54 pm

    Mmh do you really have to use your own primary key fields? If you don’t specify a primary key field, than Django automatically creates a field called id. I don’t see a a benefit from naming the fields e.g. match_id, especially as you want to access this field later, it will look like match.match_id.
    So maybe it works without your custom primary key fields.

    Also not that the option symmetrical is only taken into account if the field is referencing self, i.e. the own table, which you are not doing here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using flask-sqlalchemy to build a webapp and I have the following model(s): class
I am using the following models in my django application and want to query
I am using Rails 3.2. I have following models: Blog Comment User class Blog
I am using models in following way: class UserProfile: # Some Stuff class CompanyProfile(UserProfile):
I have a REST API using Django Tastypie. Given the following code The models
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id
I'm using the Code First approach and have the following Model: public class Person
I am using EntityFramework 4.1. I have the following model: public class User {
I am using appengine, webapp2 framework. I have the following model: class Match(db.Model): date_time
I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.