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 7172933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:43:07+00:00 2026-05-28T15:43:07+00:00

I need to enforce a composite key at the database level . The composite

  • 0

I need to enforce a composite key at the database level. The composite key is made up of five columns. In django, I can do a pseudo-composite key with:

unique_together = ("col1", "col2", "col3", "col4", "col5")

However, ALL the data being inserted into the table is from a python script outside of django. The script will simply not work if this composite primary key is not enforced (and I don’t want to address this issue at a script level).

How would I go about this issue, or is django simply out of the question to accomplish this here?

Update: I see from the comments that this is enforced at the database level. Is there also a way to get rid of the auto-incrementing primary key here? Note that none of the columns by themselves will ever be unique.

  • 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-28T15:43:08+00:00Added an answer on May 28, 2026 at 3:43 pm

    You can use unique_together for this.

    From the Django docs on unique together docs (my emphasis):

    This is a list of lists of fields that must be unique when considered together. It’s used in the Django admin and is enforced at the database level (i.e., the appropriate UNIQUE statements are included in the CREATE TABLE statement).

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

Sidebar

Related Questions

I need a little help on how I can enforce the following constraints on
I have a situation where i need to enforce a unique constraint on a
To enforce the create-drop hibernate option I need to shutdown tomcat(?), however if I
I have some relative links on my site that need to enforce https even
I have built an XML-RPC interface in Python and I need to enforce some
I need to define an Interface which has to enforce certain operator overloading to
I need to enforce TestClass order when executing tests with MSTest. The order of
I have a set of business rules that I need to enforce, such as:
Suppose I have a user table that creates strong relationships (Enforce Foreign Key Constraint)
I need to enforce character count limit in my application. I found some JavaScripts

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.