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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:10:29+00:00 2026-05-31T06:10:29+00:00

My MySQL table’s primary is a composite of 2 columns: space_id (INTEGER) and day

  • 0

My MySQL table’s primary is a composite of 2 columns: space_id (INTEGER) and day (DATE).

CREATE TABLE `ck_space_calendar_cache` (
  `space_id` int(11) NOT NULL,
  `day` date NOT NULL,
  `available` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `price` decimal(12,2) DEFAULT NULL,
  `offer` varchar(45) DEFAULT NULL,
  `presale_date` date DEFAULT NULL,
  `presale_price` decimal(12,2) DEFAULT NULL,
  `value_x` int(11) DEFAULT NULL,
  `value_y` int(11) DEFAULT NULL,
  PRIMARY KEY (`space_id`,`day`),
  KEY `space` (`space_id`),
  CONSTRAINT `space` FOREIGN KEY (`space_id`) REFERENCES `ck_space` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

It works fine in raw SQL, it complains if I try to create a duplicate, but lets me create rows the the same day or the same space_id.

However, in Yii when using new Object() and save(), it complains as if “space_id” has to be unique.

I used “Giix” to generate the model if it matters.

I tried to add this code to the model, but it didn’t help:

public function primaryKey(){
            return array('space_id', 'day');
        }
  • 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-31T06:10:30+00:00Added an answer on May 31, 2026 at 6:10 am

    Adding this code to your ActiveRecord class is okay, but should not be necessary because Yii already has that information from your MySQL table declaration.

        public function primaryKey(){
           return array('space_id', 'day');
        }
    

    When Yii complains about “space_id” to be unique, giix might have added a validation rule to rules() in your ActiveRecord class. These rules are checked before an ActiveRecord is saved and it will only save if all rules are okay. Read the Data Validation section of Definitive Guide for more information.

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

Sidebar

Related Questions

In this MySQL table definition: CREATE TABLE groups ( ug_main_grp_id smallint NOT NULL default
I've a MySQL table folders: CREATE TABLE IF NOT EXISTS `folders` ( `id` int(11)
I have a MySQL table with many numeric columns (some INT, some FLOAT). I
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
Using MySQL Table ID Date 001 2010-05-01 002 2010-06-08 Query Select ID, Date from
I have a MySql table named 'comments' : id | date | movie_id |
Let t be a mysql table and n be an integer column in it.
MySQL table with couple of fields: id - PRIMARY KEY url - CHAR(255) .
Hi I have a mysql table having the following fields A INT, B INT,
Unix time from MySQL table: 1328422844 posted via date('U') (translates to 2012-02-04 22:20:44) Displays

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.