2017-08-16 10 views
1

実行に失敗した移行があります。Laravelの移行は実行できませんが、クエリは機能します

public function up() 
{ 
    Schema::create('users_watch_history', function (Blueprint $table) { 
     $table->string('id', 36)->primary(); 
     $table->string('user_id', 36); 
     $table->string('video_id', 36); 
     $table->string('course_id', 36); 
     $table->timestamp('last_timestamp'); 
     $table->float('vid_watch', 5, 2); 
     $table->float('total_watch', 5, 2); 
     $table->text('watched_parts'); 
     $table->integer('last_position'); 
     $table->softDeletes(); 

     $table->foreign('user_id') 
      ->references('id')->on('users') 
      ->onDelete('cascade')->onUpdate('cascade'); 

     $table->foreign('video_id') 
      ->references('id')->on('videos') 
      ->onDelete('cascade')->onUpdate('cascade'); 

     $table->foreign('course_id') 
      ->references('id')->on('courses') 
      ->onDelete('cascade')->onUpdate('cascade'); 
    }); 
} 

移行が実際に私がlast_timestamp列に無効なデフォルト値に関するエラーメッセージを取得しておく実行します。

$ php artisan migrate 


    [Illuminate\Database\QueryException] 
    SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid 
    default value for 'last_timestamp' (SQL: create table 
    `users_watch_history` (`id` varchar(36) not null, `user_id` 
    varchar(36) not null, `video_id` varchar(36) not null, `course_id` 
    varchar(36) not null, `last_timestamp` timestamp not null, 
    `vid_watch` double(5, 2) not null, `total_watch` double(5, 2) not 
    null, `watched_parts` text not null, `last_position` int not null, 
    `deleted_at` timestamp null) default character set utf8 collate utf8_unicode_ci) 



    [PDOException] 
    SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'last_timestamp' 

私のMySQLバージョン

> select @@version 
+------------+ 
| @@version | 
+------------+ 
| 5.6.34-log | 
+------------+ 
1 row in set (0.20 sec) 

しかし、曲線のために私を投げねじれがある - 私は、DBのためのCLIでコマンドを作成を実行した場合、すべてが正常に動作しますか?

> create table `users_watch_history` (`id` varchar(36) not null, `user_id` varchar(36) not null, `video_id` varchar(36) not null, `course_id` varchar(36) not null, `last_timestamp` timestamp not null, `vid_watch` double(5, 2) not null, `total_watch` double(5, 2) not null, `watched_parts` text not null, `last_position` int not null, `deleted_at` timestamp null) default character set utf8 collate utf8_unicode_ci; 
Query OK, 0 rows affected (0.19 sec) 

テーブルスキーマ:移行介して実行しないように、この有効なクエリを引き起こしている可能性が何

> show create table users_watch_history \G 
*************************** 1. row *************************** 
     Table: users_watch_history 
Create Table: CREATE TABLE `users_watch_history` (
    `id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, 
    `user_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, 
    `video_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, 
    `course_id` varchar(36) COLLATE utf8_unicode_ci NOT NULL, 
    `last_timestamp` timestamp NOT NULL, 
    `vid_watch` double(5,2) NOT NULL, 
    `total_watch` double(5,2) NOT NULL, 
    `watched_parts` text COLLATE utf8_unicode_ci NOT NULL, 
    `last_position` int(11) NOT NULL, 
    `deleted_at` timestamp NULL DEFAULT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 
1 row in set (0.17 sec) 

任意のアイデア?

+0

'explicit_defaults_for_timestamp' MySQL変数を確認してください。コンソールとプロジェクトの違いは、異なる環境(その変数の値が異なる)にある可能性があります。 https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp – Axalix

答えて

2

MySQL厳密モードを無効にします。問題を修正する必要がありますnullable()これら の$table->timestamp('last_timestamp')->nullable();

一つ へstrict' => false

  • 'strict' => true に' または追加設定し、あなたのlaravel設定ファイルdatabase.php

    • 、。

  • 関連する問題