mysql - percona 时间戳默认 0 不为空

标签 mysql laravel percona

我已经使用 Brew 在我的 mac 上安装了 percona-server 用于本地开发

┌─(veilig@Jamies-MacBook-Air:s018)──────────────(~/api.foo.com)─┐
└─(13:25:%)── brew info percona-server                                                      ──(Wed,Sep03 - feature/users)─┘
percona-server: stable 5.6.19-67.0 (bottled)

我正在尝试运行此查询

create table `courses` (
   `id` varchar(36) not null,
   `title` varchar(255) not null,
   `created_at` timestamp default 0 not null,
   `updated_at` timestamp default 0 not null,
   `tokens` int not null default '0',
   `product_id` int null,
   `track_id` varchar(36) not null
) default character set utf8 collate utf8_unicode_ci

当它必须创建 updated_at 列时它会窒息,因为 timestamp default 0。 sql stmt 是在我的 Laravel 4.2 PHP 应用程序中创建的。

有没有办法放宽这些限制以使其发挥作用?

这是准确的错误

veilig@localhost (api_foo_com) > create table `courses` (`id` varchar(36) not null, `title` varchar(255) not null, `created_at` timestamp default 0 not null, `updated_at` timestamp default 0 not null, `tokens` int not null default '0', `product_id` int null, `track_id` varchar(36) not null) default character set utf8 collate utf8_unicode_ci;
ERROR 1067 (42000): Invalid default value for 'created_at'

当我们在我的同事数据库上尝试这个时,我们没有遇到这个问题。他在运行:

mysql Ver 14.14 Distrib 5.5.38,适用于使用 readline 6.2 的 debian-linux-gnu (x86_64)

最佳答案

必须从我的 /etc/my.cnf(或您的 MySQL 配置所在的任何位置)中删除两个 sql-mode 以允许 laravel 迁移正常工作。

NO_ZERO_DATENO_ZERO_IN_DATE

关于mysql - percona 时间戳默认 0 不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25650395/

相关文章:

mysql - 分区 MySQL : Error Code 1679 when trying to partion a table

php - 如何在 Laravel 中扩展 PHPUnit?

laravel - 如何使用 db::raw 对 Laravel fluent 进行更新查询

mysql - 有人使用 pt-online-schema-change 来更改包含 1x 百万个条目的表吗?

MySQL:为什么外键失败?

php - 2 通过不同、求和、计数进行分组 : PHP MySQL

mysql - #1089 在 phpMyAdmin 中创建表时出错

mysql - SQL : Returning a list of all the classes that 2 specific students are both attending

php - Laravel 形式在 Debug模式下提交但在正常模式下不起作用

c++ - 解决来自 const 的无效转换