Ankündigung

Einklappen
Keine Ankündigung bisher.

Laravel Migration

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Laravel Migration

    Hallo,

    ich habe in Laravel folgendes Migrations Script:

    PHP-Code:
    $tableName 'oxacceptedterms';
    Schema::dropIfExists($tableName);
    Schema::create($tableName, function (Blueprint $table) {
        
    $table->engine 'MyISAM';
         
    $table->char('OXUSERID'32)->charset('latin1')->collation('latin1_general_ci')->comment('User id (oxuser)');
        
    $table->char('OXSHOPID'32)->charset('latin1')->collation('latin1_general_ci')->default('')->comment('Shop id (oxshops)');
        
    $table->char('OXTERMVERSION'32)->charset('latin1')->collation('latin1_general_ci')->default('')->comment('Terms version');
        
    $table->dateTime('OXACCEPTEDTIME')->default('0000-00-00 00:00:00')->comment('Time, when terms were accepted');
        
    $table->timestamp('OXTIMESTAMP')->default(DB::raw('CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP'))->comment('Timestamp');
        
    $table->primary(['OXUSERID''OXSHOPID']);
    });
    DB::statement("ALTER TABLE `{$tableName}` comment 'Shows which users has accepted shop terms'"); 
    Wenn ich die Migration nun ausführe, kommt der Fehler:
    Code:
    SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'OXACCEPTEDTIME' (SQL: create table `oxacceptedterms` (`OXUSERID` char(32) character set latin1 collate latin1_general_ci not null comment 'User id (oxuser)', `OXSHOPID` char(32) character set latin1 collate latin1_general_ci not null default '' comment 'Shop id (oxshops)', `OXTERMVERSION` char(32) character set latin1 collate latin1_general_ci not null default '' comment 'Terms version', `OXACCEPTEDTIME` datetime not null default '0000-00-00 00:00:00' comment 'Time, when terms were accepted', `OXTIMESTAMP` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment 'Timestamp') default character set utf8 collate utf8_unicode_ci engine = MyISAM)
    Kopiere ich das SQL Statement und führe es von Hand aus (phpMyAdmin oder MySQL Console) dann geht es ohne Probleme. Jemand eine Idee?

    Lieben Gruß
    Kerstel

  • #2
    Hi,

    prüfe mal, ob auf dem Server NO_ZERO_DATE aktiviert ist ( https://dev.mysql.com/doc/refman/5.7...e_no_zero_date )

    Prinzipiell würde ich dir aber empfehlen, nicht 0000-00... als default zu nehmen sondern NULL. Dann hast du sauberere abgedeckt, wenn kein Datum gesetzt wurde und nutzt nicht ein eigentlich invalides Datum.

    Grüße,
    Funfare

    Kommentar

    Lädt...
    X