Menu

#1747 (ok 3.1.2) Can't NULL a column with a relation defined

3.1.1
fixed
None
1
2015-01-28
2005-08-06
No

1. Create a table 't1' with a column 'c1' of type int
2. Create a table 't2' with a NULLABLE column 'c2' of
type int
3. Insert a few records into t1
4. In Relationship View, refer t2.c2 -> t1.c1
5. Insert a few records into t2.
6. Edit a record in t2, check "NULL" checkbox on "c2"
and try to save.
7. Saved value of c2 will be 0 and not NULL.

Discussion

1 2 > >> (Page 1 of 2)
  • Marc Delisle

    Marc Delisle - 2005-08-20

    Logged In: YES
    user_id=210714

    Moved to support. At step 4 you are defining a relation, but
    to do this, I think you defined a primary key on c2. While
    doing this, MySQL removed the NULL attribute because "a
    primary key column cannot be NULL".
    http://dev.mysql.com/doc/mysql/en/alter-table.html

     
  • Marc Delisle

    Marc Delisle - 2005-08-20
    • labels: 509097 -->
    • assigned_to: nobody --> lem9
     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    I insist it is a bug. Why can I do the same thing manually,
    through UPDATE `t2` SET `c2` = NULL, but not through that
    checkbox?

    And it's perfectly legal data structure. Let me show you:

    `category`
    --------------------------------
    id | desc
    -----------------------------------
    1 | Liquid
    2 | Fruit
    --------------------------------

    `items`
    --------------------------------
    id | desc | category |
    -----------------------------------
    1 | Water | 1
    2 | Orange | 2
    3 | Apple | 2
    4 | Cat | NULL // Category
    unknown and/or not yet assigned
    --------------------------------

    So in my example:
    1) `items`.`category` has a foreign key relationship to
    `category`'.`id`;
    2) `items`.`category` is set to NULLable (and perfectly
    holds NULLs if I add them manually).

    AFAIK that's so-called 'weak' foreign key relatioship.

     
  • Wesha the Leopard

    • priority: 5 --> 6
     
  • Marc Delisle

    Marc Delisle - 2005-08-20

    Logged In: YES
    user_id=210714

    Oh, I thought you were talking about the structure of c2
    losing its NULL. Which MySQL and phpMyAdmin versions are you
    using?

    Please add to this tracker the export of structure and data
    for your 2 test tables, ensure you use "add into comments
    relations".

     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    CREATE TABLE `purchase_grouping` (
    `group` int(10) unsigned NOT NULL auto_increment,
    `refer` int(11) unsigned default NULL,
    PRIMARY KEY (`group`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

    --
    -- RELATIONS FOR TABLE `purchase_grouping`:
    -- `refer`
    -- `transactions` -> `id`
    --

    CREATE TABLE `transactions` (
    `id` int(11) unsigned NOT NULL auto_increment,
    `post_date` date default NULL,
    `amount` decimal(8,2) NOT NULL default '0.00',
    `refer_tran` int(11) unsigned default NULL,
    `refer_purchase` int(11) unsigned default NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

    --
    -- RELATIONS FOR TABLE `transactions`:
    -- `refer_purchase`
    -- `purchase_grouping` -> `group`
    -- `refer_tran`
    -- `transactions` -> `id`
    --

     
  • Marc Delisle

    Marc Delisle - 2005-08-21

    Logged In: YES
    user_id=210714

    With phpMyAdmin 2.6.3-pl1, under Firefox 1.0.6 with
    Javascript enabled, when editing a row for the
    purchase_grouping or the transactions table, I have no
    problem checking the Null box: this saves a NULL value in
    the corresponding field.
    For example, this query is generated:
    UPDATE `purchase_grouping` SET `refer` = NULL WHERE `group`
    =1234 LIMIT 1 ;

     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    phpMyAdmin 2.6.3-pl1, Mozilla 1.7.11, JS enabled, JS
    console doesnt show any errors.

    1) 'Browse' Purchase_grouping' table.
    2) Click to edit a yet unreferred item (in my case id = 4);
    3) Change 'refer' column to some value that exists in the
    related table, say 3708.
    4) Click GO.
    5) Displayed:
    --------------------------------------------------------------------------------------
    Affected rows: 1
    SQL query:
    UPDATE `purchase_grouping` SET `refer` = '3708' WHERE
    `group` =4 LIMIT 1 ;
    --------------------------------------------------------------------------------------
    6) Click on the same item again to edit it.
    7) Check 'NULL' checxbox and click GO
    8) Displayed:
    --------------------------------------------------------------------------------------
    No change
    --------------------------------------------------------------------------------------

     
  • Marc Delisle

    Marc Delisle - 2005-09-28

    Logged In: YES
    user_id=210714

    phpMyAdmin 2.6.4-pl1, Firefox 1.0.7, JS enabled. I do
    exactly your test.

    After step 7, I get:
    UPDATE `purchase_grouping` SET `refer` = NULL WHERE `group`
    =4 LIMIT 1 ;

     
  • Marc Delisle

    Marc Delisle - 2005-09-28
    • priority: 6 --> 5
     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    I guess we won't get anywhere this way, would you please
    email me privately -- w-e-s-h-a (-at-) h-o-t-m-a-i-l.c-o-m
    so I can arrange direct shell access for you to the system
    in subject?

     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    P.S. I guess it's something about multiple relations and/or
    data set size. When I try it on the actual database (6
    tables, ~~5000 records), it fails as described in the bug.
    When I export and reimport it under a different name through
    phpMyAdmin, it also fails. When I try to cut it down to a
    more reasonable size (3 tables, 10 records), it starts
    working properly.

     
  • Marc Delisle

    Marc Delisle - 2005-10-01

    Logged In: YES
    user_id=210714

    Moved to support. Emailed privately, waiting for answer.

     
  • Marc Delisle

    Marc Delisle - 2005-10-15

    Logged In: YES
    user_id=210714

    No reply from user -> closed.

     
  • Marc Delisle

    Marc Delisle - 2005-10-15
    • status: open --> closed
     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    Sorry about the delay, at the moment I'm busy with other
    things, but I still experience this problem. Let's just
    give it the lowest priority possible for now, but not close,
    please?

     
  • Wesha the Leopard

    • priority: 5 --> 1
    • status: closed --> open
     
  • Marc Delisle

    Marc Delisle - 2006-03-09
    • priority: 1 --> 3
    • assigned_to: lem9 --> nobody
     
  • Michal Čihař

    Michal Čihař - 2006-03-14

    Logged In: YES
    user_id=192186

    Still no reply.

     
  • Michal Čihař

    Michal Čihař - 2006-03-14
    • status: open --> pending
     
  • Wesha the Leopard

    Logged In: YES
    user_id=410621

    Okay, I found how exactly ro reproduce it.

    Correction to step 3: Insert MANY records in t1, enough so
    the relationship field will be displayed as "TEXT field +
    LOOKUP button" on step 6, not as a dropdown.

    Correction to step 6: Check NULL checkbox on C2, and notice
    that whatever is currently entered in C2 field has not been
    cleared; then, click SAVE.

    It seems that the content of the field has priority over
    "NULL" checkbox, though I would expect it the other way
    around: if NULL is checked, the field content should be
    cleared when (or prior to) saving

     
  • Wesha the Leopard

    • status: pending --> open
     
  • Michal Čihař

    Michal Čihař - 2006-04-08

    Logged In: YES
    user_id=192186

    Moving back to bugs.

     
  • Marc Delisle

    Marc Delisle - 2006-06-09
    • assigned_to: nobody --> lem9
    • status: open --> pending
     
  • Marc Delisle

    Marc Delisle - 2006-06-09

    Logged In: YES
    user_id=210714

    Cannot reproduce your problem with your corrected steps, in
    phpMyAdmin 2.8.1. I use this structure:
    --
    -- Table structure for table `t1`
    --

    CREATE TABLE `t1` (
    `c1` int(11) NOT NULL,
    PRIMARY KEY (`c1`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    --
    -- Dumping data for table `t1`
    --

    INSERT INTO `t1` VALUES (1);
    INSERT INTO `t1` VALUES (2);
    INSERT INTO `t1` VALUES (3);
    INSERT INTO `t1` VALUES (4);
    INSERT INTO `t1` VALUES (5);
    INSERT INTO `t1` VALUES (6);
    INSERT INTO `t1` VALUES (7);
    INSERT INTO `t1` VALUES (8);
    INSERT INTO `t1` VALUES (9);
    INSERT INTO `t1` VALUES (11);
    INSERT INTO `t1` VALUES (12);
    INSERT INTO `t1` VALUES (13);
    INSERT INTO `t1` VALUES (14);
    INSERT INTO `t1` VALUES (15);

    -- --------------------------------------------------------

    --
    -- Table structure for table `t2`
    --

    CREATE TABLE `t2` (
    `c2` int(11) default '0',
    UNIQUE KEY `c2` (`c2`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    --
    -- RELATIONS FOR TABLE `t2`:
    -- `c2`
    -- `t1` -> `c1`
    --

    --
    -- Dumping data for table `t2`
    --

    INSERT INTO `t2` VALUES (9);
    INSERT INTO `t2` VALUES (11);
    INSERT INTO `t2` VALUES (15);

     
1 2 > >> (Page 1 of 2)
MongoDB Logo MongoDB