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

  • Home
  • SEARCH
  • 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 6597915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:16:16+00:00 2026-05-25T18:16:16+00:00

I want my ip and stream_id combination to be unique, so I wrote this

  • 0

I want my ip and stream_id combination to be unique, so I wrote this model:

# Votes
class Vote(models.Model):
    # The stream that got voted
    stream = models.ForeignKey(Stream)

    # The IP adress of the voter
    ip = models.CharField(max_length = 15)

    vote = models.BooleanField()

    unique_together = (("stream", "ip"),)

But for some reason it produces this table, skipping the ip

mysql> SHOW CREATE TABLE website_vote;
+--------------+---------------------------------------------+
| Table        | Create Table                                |
+--------------+---------------------------------------------+
| website_vote | CREATE TABLE `website_vote` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `stream_id` int(11) NOT NULL,
  `ip` varchar(15) NOT NULL,
  `vote` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `website_vote_7371fd6` (`stream_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+--------------+---------------------------------------------+
1 row in set (0.00 sec)

Why doesn’t it include ip in the key? For the record I am aware that the unique_together line can be written without nesting the tuples, but that has no bearing on the issue

  • 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-25T18:16:16+00:00Added an answer on May 25, 2026 at 6:16 pm

    unique_together needs to be in the models Meta class. See docs.

    class Vote(models.Model):
        # The stream that got voted
        stream = models.ForeignKey(Stream)
    
        # The IP adress of the voter
        ip = models.CharField(max_length = 15)
    
        vote = models.BooleanField()
    
        class Meta:
            unique_together = (("stream", "ip"),)
    

    Also, there’s a builtin IPAddressField model field. See the docs here.

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

Sidebar

Related Questions

I want to write a String to a Stream (a MemoryStream in this case)
I have a stream of data that I want to place into a container.
I have this class I want to serialize: (the private attr's) class Task {
I have an incoming stream of messages, and want a window that allows the
I want to create/show an activity stream of everything that has been published/commented on
I have seen in this post that if you want to create a new
I want to serialize a 'Player' class and send it over my network stream
I want to view the stream of the RGB data color stream on an
I want to capture and stream audio using JMF 2.1.1e in RTP format. I
I want to get the video stream from my webcam using python and OpenCV,

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.