十月 CMS - 第 1 行 'content' 列的数据太长

October CMS - Data too long for column 'content' at row 1

我在将字段保存到数据库时出错,这给了我错误:字符串数据,右截断:1406 第 1 行的 'content' 列数据太长。

但是数据库中的字段设置为类型:字符串,长度为 191。我相信这会转换为 varchar。

还有其他人有这个吗?

从上面的答案复制

VARCHAR(X) Case: user name, email, country, subject, password

TEXT Case: messages, emails, comments, formatted text, html, code, images, links

MEDIUMTEXT Case: large json bodies, short to medium length books, csv strings

LONGTEXT Case: textbooks, programs, years of logs files, harry potter and the goblet of fire, scientific research logging

您应该将帖子或页面内容(包含大量text/html的内容)存储为String

改为使用 TEXT 作为 MySQL 列类型,这样可以在其中输入足够的字符。

在您的迁移文件中使用它,它会更改您的列数据类型,然后您可以毫无问题地将 html 内容保存到其中。

public function up()
{
    Schema::table('the_table_name', function () {
        $table->longText('columnName')->change();
    });
}

public function down()
{
    Schema::dropIfExists('the_table_name');
}