我想申请以下迁移:如何制作学说支持时间戳列?
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随着composer require mmerian/doctrine-timestamp=dev-master
,我能够安装包,然后才Schema::table
声明说Type::addType('timestamp', 'DoctrineTimestamp\DBAL\Types\Timestamp');
,但现在我已经得到了其他错误:
[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');
但它并没有帮助。迁移成功,但列定义不会更改。
快,让你的'composer.json' – maximkou
您可以手动添加https://github.com/mmerian/doctrine-timestamp/blob/ master/lib/DoctrineTimestamp/DBAL/Types/Timestamp.php到您的项目 –