Laravel 的 timestamp 好像默认是没有索引的?

不过在用where查询的时候,不是的自己增加一下索引吗,要不然性能怕会下降

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 2

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ChangeCreatedAtToSaleTaskOrdersTable extends Migration
{
/**

  • Run the migrations.
  • @return void
    */
    public function up()
    {
    Schema::table('sale_task_orders', function (Blueprint $table) {
    $table->timestamp('created_at')->nullable()->index()->change();
    });
    }

}

用这个方式增加索引竟然会抛出异常
$ php artisan migrate

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(). If this error occurs during database introspection then you
might have forgotten to register all database types for a Doctrine Type. Use Ab
stractPlatform#registerDoctrineTypeMapping() or have your custom types implement
Type#getMappedDatabaseTypes(). If the type name is empty you might have a probl
em with the cache or forgot some mapping information.

at C:\wamp64\www\youyu\vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.ph
p:283
279| @return \Doctrine\DBAL\DBALException
280|
/
281| public static function unknownColumnType($name)
282| {

283| return new self('Unknown column type "'.$name.'" requested. Any
Doctrine type that you use has ' .
284| 'to be registered with \Doctrine\DBAL\Types\Type::addType()
. You can get a list of all the ' .
285| 'known types with \Doctrine\DBAL\Types\Type::getTypesMap().
If this error occurs during database ' .
286| 'introspection then you might have forgotten to register al
l database types for a Doctrine Type. Use ' .
287| 'AbstractPlatform#registerDoctrineTypeMapping() or have you
r custom types implement ' .

Exception trace:

1 Doctrine\DBAL\DBALException::unknownColumnType("timestamp")
C:\wamp64\www\youyu\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\Type.php:
189

2 Doctrine\DBAL\Types\Type::getType("timestamp")
C:\wamp64\www\youyu\vendor\laravel\framework\src\Illuminate\Database\Schem
a\Grammars\ChangeColumn.php:150

Please use the argument -v to see more details.

5年前 评论

好像没有timestramp这个字段 类型,你们是怎么解决的

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!