我正在尝试应用以下迁移:
Schema::table('users', function (Blueprint $table) {
$table->timestamp('created_at')->useCurrent()->change();
});
但是artisan
说:
[Doctrine\DBAL\DBALException]
Unknown column type "timestamp" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL
\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). I
f this error occurs during database introspection then you might have forgot to register all database types for a
Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMapp
edDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping inform
ation.
当我尝试安装mmerian/doctrine-timestamp
( composer install mmerian/doctrine-timestamp
) 时,composer
说:
[InvalidArgumentException]
Could not find package mmerian/doctrine-timestamp at any version for your minimum-stability (stable). Check the pa
ckage spelling or your minimum-stability
我该怎么办?
UPD With composer require mmerian/doctrine-timestamp=dev-master
,我能够安装软件包,然后在语句Type::addType('timestamp', 'DoctrineTimestamp\DBAL\Types\Timestamp');
之前添加Schema::table
,但现在我遇到了另一个错误:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at' (SQL: ALTER TABLE u
sers CHANGE created_at created_at INT DEFAULT 'CURRENT_TIMESTAMP' NOT NULL)
UPD我再次检查了它是否适用于mmerian/doctrine-timestamp
,因为当时我只添加了文档中的第一行(或者文档已更新):
Type::addType('timestamp', 'DoctrineTimestamp\DBAL\Types\Timestamp');
DB::getDoctrineConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('Timestamp', 'timestamp');
但这也无济于事。迁移成功,但列定义没有改变。