【问题标题】:Field 'cover' doesn't have a default value字段“cover”没有默认值
【发布时间】:2021-04-21 19:25:06
【问题描述】:

我正在使用 tx_sfbooks 扩展程序将图书添加到我的网站。

当我添加新记录时,我收到以下错误:

2: SQL error: 'Field 'cover' doesn't have a default value' (tx_sfbooks_domain_model_book:NEW60807a6c5dce2359862008)

我尝试在表 tx_sfbooks_domain_model_book 中为字段 cover 添加默认值,但在 mysql 上出现错误,因为该字段是 BLOB 类型。

我也试过禁用严格的 SQL 模式:https://stackoverflow.com/a/45059826/11541354

但总是同样的错误。

这是架构:

#
# Table structure for table 'tx_sfbooks_domain_model_book'
#
CREATE TABLE tx_sfbooks_domain_model_book
(
    number       tinytext                     NOT NULL,
    title        tinytext                     NOT NULL,
    path_segment varchar(2048),
    subtitle     tinytext                     NOT NULL,
    author       tinytext                     NOT NULL,
    isbn         tinytext                     NOT NULL,
    series       int(11) unsigned DEFAULT '0' NOT NULL,
    category     int(11) unsigned DEFAULT '0' NOT NULL,
    description  text                         NOT NULL,
    extras       blob                         NOT NULL,
    cover        blob                         NOT NULL,
    cover_large  blob                         NOT NULL,
    sample_pdf   blob                         NOT NULL,
    year         varchar(4)       DEFAULT ''  NOT NULL,
    location1    int(11) unsigned DEFAULT '0' NOT NULL,
    location2    int(11) unsigned DEFAULT '0' NOT NULL,
    location3    int(11) unsigned DEFAULT '0' NOT NULL
);

我正在使用 MySQL 8.0.23

【问题讨论】:

  • 查看该表的架构!或者看的时候看不明显就给我们看看
  • 如果架构中没有设置默认值,则必须在 INSERT 中为该列传递一个值
  • 由于 cover 只是一个文件引用(关系)字段 github.com/evoWeb/sf_books/blob/develop/Configuration/TCA/… ,它实际上应该是一个整数列。如果没有 MySQL strict_mode,整数可以保存到 BLOB。恕我直言,这是扩展程序 TCA 中的错误。

标签: mysql typo3


【解决方案1】:

我通过关闭 Mysql strict mode 解决了这个问题:

mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';" 

要验证,请运行以下命令:

 mysql -u root -p -e "SELECT @@GLOBAL.sql_mode;"

你应该看到:

+---------------+------------------------+
| Variable_name | Value                  |
+---------------+------------------------+
| sql_mode      | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+

【讨论】:

    猜你喜欢
    • 2012-09-25
    • 2018-03-19
    • 2014-11-09
    • 2015-07-07
    • 2019-11-22
    • 2018-07-29
    • 2018-07-09
    • 2018-07-14
    • 2020-05-29
    相关资源
    最近更新 更多