无法在MySQL 5.7中更改表列类型

时间:2019-06-11 02:56:51

标签: mysql alter

我在MySQL 5.7数据库和其余的SQL语句中都有此表:

create table m_workflow
    (
        id bigint(10) auto_increment primary key,
        course bigint(10) default 0 not null,
        name varchar(255) default '' not null,
        intro longtext not null,
        introformat smallint(4) default 0 not null,
        recommendationstitle varchar(255) null,
        recommendintro longtext null,
        recommendintroformat bigint(10) default 1 null,
        timeopen bigint(10) default 0 not null,
        timeclose bigint(10) default 0 not null,
        timelimit bigint(10) default 0 not null,
        timecreated bigint(10) default 0 not null,
        timemodified bigint(10) default 0 not null
    )
    comment 'The settings for each workflow.';

    create index m_work_cou_ix on m_workflow (course);

    INSERT INTO m_workflow (course, name, intro, introformat) VALUES (1, 'aaa', 'aaaa', 1);
    INSERT INTO m_workflow (course, name, intro, introformat) VALUES (1, 'aaa', 'aaaa', 1);

    ALTER TABLE m_workflow MODIFY COLUMN recommendationstitle LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL after introformat;

这里的问题是它在ALTER列语句上失败,并显示错误:

Data truncated for column 'recommendationstitle' at row 1

如果我在Recommendationstitle字段中添加了一些文字,那么转换就可以了。

这是意料之中的还是我做错了什么?

这是SQL提琴-http://www.sqlfiddle.com/#!9/10934c/2

1 个答案:

答案 0 :(得分:1)

您正在尝试将其从NULL修改为NOT NULL。 当前存在的NULL值记录导致该问题。