不知道你啥意思,是不是不希望parent_id 这个为null。
ALTER TABLE d_d_category MODIFY COLUMN parent_id INT(12) DEFAULT 0 NOT NULL ;

解决方案 »

  1.   

    不知道你啥意思,是不是不希望parent_id 这个为null。
    ALTER TABLE d_d_category MODIFY COLUMN parent_id INT(12) DEFAULT 0 NOT NULL ;就是不希望他为空用这个语句后报
    Data truncated for column parent_id
      

  2.   


    是报了DATA truncated FOR COLUMN 'parent_id' AT ROW 1 这么个警告,但是没影响呀,难道你没有看你的表结构的parent_id字段改变了吗?同时那个null值也变成0 了
      

  3.   

    没有啊还是null 报的是error  难道因为 parent_id是外键 改不了
      

  4.   

    -- 我这边单单的这张表没有报任何问题,外键怎么可能为null 呢,你关联的哪个表呀?
      

  5.   

    如果说parent_id 是外键,那么parent_id 也是另外一张表的主键呀,主键怎么可能null 。你看看你的问题吧
      

  6.   

    建表语言是这样子的  product表还与其他表有关联 麻烦您看一下
    DROP TABLE IF EXISTS d_d_category;
    CREATE TABLE d_d_category (
      id int(12) NOT NULL auto_increment,
      turn int(3) default '10',
      en_name varchar(50) NOT NULL,
      cn_name varchar(50) NOT NULL,
      parent_id int(12),
      category_value varchar(200) default NULL,
      PRIMARY KEY  (id),
      UNIQUE KEY en_name (en_name),
      UNIQUE KEY category_value (category_value)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS d_d_product;
    CREATE TABLE d_d_product (
      id int(12) NOT NULL auto_increment,
      category_id int(12) NOT NULL,
      product_name varchar(100) NOT NULL,
      description varchar(100) default NULL,
      add_time bigint(20) default NULL,
      fixed_price double NOT NULL,
      dang_price double NOT NULL,
      keywords varchar(200) default NULL,
      has_deleted int(1) NOT NULL default '0',
      product_pic varchar(200) default NULL,
      PRIMARY KEY  (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;alter table d_d_category add(
    FOREIGN KEY (parent_id) REFERENCES d_d_category (id) ON UPDATE CASCADE
    );
    alter table d_d_product add(
    FOREIGN KEY (category_id) REFERENCES d_d_category (id) ON UPDATE CASCADE
      

  7.   

    不跟你纠结这些问题了,你的目的不是要修改数据吗,既然有外键的约束,那就disable 约束。
    -- 操作:
    SET FOREIGN_KEY_CHECKS = 0;
    UPDATE d_d_category SET parent_id=0 WHERE id=1;
    SET FOREIGN_KEY_CHECKS = 1;