1. <tfoot id='VhTN2'></tfoot>
      2. <i id='VhTN2'><tr id='VhTN2'><dt id='VhTN2'><q id='VhTN2'><span id='VhTN2'><b id='VhTN2'><form id='VhTN2'><ins id='VhTN2'></ins><ul id='VhTN2'></ul><sub id='VhTN2'></sub></form><legend id='VhTN2'></legend><bdo id='VhTN2'><pre id='VhTN2'><center id='VhTN2'></center></pre></bdo></b><th id='VhTN2'></th></span></q></dt></tr></i><div id='VhTN2'><tfoot id='VhTN2'></tfoot><dl id='VhTN2'><fieldset id='VhTN2'></fieldset></dl></div>

        <small id='VhTN2'></small><noframes id='VhTN2'>

          <bdo id='VhTN2'></bdo><ul id='VhTN2'></ul>

        <legend id='VhTN2'><style id='VhTN2'><dir id='VhTN2'><q id='VhTN2'></q></dir></style></legend>

        如何让学说支持时间戳列?

        How do I make doctrine support timestamp columns?(如何让学说支持时间戳列?)

        <legend id='3fTg7'><style id='3fTg7'><dir id='3fTg7'><q id='3fTg7'></q></dir></style></legend>
      3. <small id='3fTg7'></small><noframes id='3fTg7'>

          <bdo id='3fTg7'></bdo><ul id='3fTg7'></ul>

                <i id='3fTg7'><tr id='3fTg7'><dt id='3fTg7'><q id='3fTg7'><span id='3fTg7'><b id='3fTg7'><form id='3fTg7'><ins id='3fTg7'></ins><ul id='3fTg7'></ul><sub id='3fTg7'></sub></form><legend id='3fTg7'></legend><bdo id='3fTg7'><pre id='3fTg7'><center id='3fTg7'></center></pre></bdo></b><th id='3fTg7'></th></span></q></dt></tr></i><div id='3fTg7'><tfoot id='3fTg7'></tfoot><dl id='3fTg7'><fieldset id='3fTg7'></fieldset></dl></div>
                  <tbody id='3fTg7'></tbody>
              • <tfoot id='3fTg7'></tfoot>

                  本文介绍了如何让学说支持时间戳列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试应用以下迁移:

                  I'm trying to apply the following migration:

                  Schema::table('users', function (Blueprint $table) {
                      $table->timestamp('created_at')->useCurrent()->change();
                  });
                  

                  但是artisan 说:

                    [DoctrineDBALDBALException]
                    Unknown column type "timestamp" requested. Any Doctrine type that you use has to be registered with DoctrineDBAL
                    TypesType::addType(). You can get a list of all the known types with DoctrineDBALTypesType::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 说:

                  When I try to install mmerian/doctrine-timestamp (composer install mmerian/doctrine-timestamp), composer says:

                    [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,我能够安装包,然后添加 Type::addType('timestamp', 'DoctrineTimestampDBALTypesTimestamp');Schema::table 语句之前,但现在我有另一个错误:

                  UPD With composer require mmerian/doctrine-timestamp=dev-master, I was able to install the package, then added Type::addType('timestamp', 'DoctrineTimestampDBALTypesTimestamp'); before Schema::table statement, but now I've got the other error:

                    [IlluminateDatabaseQueryException]
                    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,因为我当时只添加了文档中的第一行(或者文档已更新):

                  UPD I checked again if it works with mmerian/doctrine-timestamp, since I added only first of the lines from the docs back then (or the doc was updated):

                  Type::addType('timestamp', 'DoctrineTimestampDBALTypesTimestamp');                                          
                  DB::getDoctrineConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('Timestamp', 'timestamp');
                  

                  但这也无济于事.迁移成功,但列定义没有改变.

                  But it doesn't help as well. The migration succeeds, but the column definition doesn't change.

                  推荐答案

                  正如人们所见,mmerian/doctrine-timestamp 并没有解决问题.首先,在这一行之后 $table->getColumns()['created_at']

                  As one can see, mmerian/doctrine-timestamp doesn't solve the issue. First, after this line $table->getColumns()['created_at'] is

                  class DoctrineDBALSchemaColumn#520 (16) {
                    protected $_type => class DoctrineDBALTypesDateTimeType#504 (0) { }
                    protected $_length => NULL
                    protected $_precision => int(10)
                    protected $_scale => int(0)
                    protected $_unsigned => bool(false)
                    protected $_fixed => bool(false)
                    protected $_notnull => bool(true)
                    protected $_default => string(17) "CURRENT_TIMESTAMP"
                    protected $_autoincrement => bool(false)
                    protected $_platformOptions => array(0) { }
                    protected $_columnDefinition => NULL
                    protected $_comment => NULL
                    protected $_customSchemaOptions => array(0) { }
                    protected $_name => string(10) "created_at"
                    protected $_namespace => NULL
                    protected $_quoted => bool(false)
                  }
                  

                  $this->getTableWithColumnChanges($blueprint, $table)->getColumns()['created_at']

                  class DoctrineDBALSchemaColumn#533 (16) {
                    protected $_type => class DoctrineTimestampDBALTypesTimestamp#513 (0) { }
                    protected $_length => NULL
                    protected $_precision => int(10)
                    protected $_scale => int(0)
                    protected $_unsigned => bool(false)
                    protected $_fixed => bool(false)
                    protected $_notnull => bool(true)
                    protected $_default => string(17) "CURRENT_TIMESTAMP"
                    protected $_autoincrement => bool(false)
                    protected $_platformOptions => array(0) { }
                    protected $_columnDefinition => NULL
                    protected $_comment => NULL
                    protected $_customSchemaOptions => array(0) { }
                    protected $_name => string(10) "created_at"
                    protected $_namespace => NULL
                    protected $_quoted => bool(false)
                  }
                  

                  所以,首先我在这里看不到有关 ON UPDATE 部分的信息.其次,唯一的区别是 $_type 值.这一行之后我可以确认什么, $tableDiff->changedColumns['created_at']->changedProperties

                  So, first I can't see information about ON UPDATE part here. Second, the onle difference is $_type value. What I can confirm after this line, $tableDiff->changedColumns['created_at']->changedProperties is

                  array(1) {
                    [0] => string(4) "type"
                  }
                  

                  然后,当 生成 ALTER TABLE 声明,归结为这个

                  Then, when generating ALTER TABLE statement, it all comes down to this

                  public function getDefaultValueDeclarationSQL($field)
                  {
                      $default = empty($field['notnull']) ? ' DEFAULT NULL' : '';
                      if (isset($field['default'])) {
                          $default = " DEFAULT '".$field['default']."'";
                          if (isset($field['type'])) {
                              if (in_array((string) $field['type'], array("Integer", "BigInt", "SmallInt"))) {
                                  $default = " DEFAULT ".$field['default'];
                              } elseif (in_array((string) $field['type'], array('DateTime', 'DateTimeTz')) && $field['default'] == $this->getCurrentTimestampSQL()) {
                                  $default = " DEFAULT ".$this->getCurrentTimestampSQL();
                              } elseif ((string) $field['type'] == 'Time' && $field['default'] == $this->getCurrentTimeSQL()) {
                                  $default = " DEFAULT ".$this->getCurrentTimeSQL();
                              } elseif ((string) $field['type'] == 'Date' && $field['default'] == $this->getCurrentDateSQL()) {
                                  $default = " DEFAULT ".$this->getCurrentDateSQL();
                              } elseif ((string) $field['type'] == 'Boolean') {
                                  $default = " DEFAULT '" . $this->convertBooleans($field['default']) . "'";
                              }
                          }
                      }
                      return $default;
                  }
                  

                  这一行应该是检查Timestamp类型以将'CURRENT_TIMESTAMP'转换为CURRENT_TIMESTAMP.这在 mmerian/doctrine-timestamp 中可能吗?这个问题暂时悬而未决.此检查很可能会解决我的特定问题.但现在我要摆脱这个:

                  Somewhere around this line there supposed to be a check for Timestamp type to turn 'CURRENT_TIMESTAMP' into CURRENT_TIMESTAMP. Is this possible within mmerian/doctrine-timestamp? That question is left open for now. This check would most likely solve my particular issue. But for now I'm going to get away with this:

                  DB::statement('ALTER TABLE users MODIFY COLUMN created_at
                      TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP');
                  

                  这篇关于如何让学说支持时间戳列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)
                      1. <tfoot id='btdmN'></tfoot>
                      2. <i id='btdmN'><tr id='btdmN'><dt id='btdmN'><q id='btdmN'><span id='btdmN'><b id='btdmN'><form id='btdmN'><ins id='btdmN'></ins><ul id='btdmN'></ul><sub id='btdmN'></sub></form><legend id='btdmN'></legend><bdo id='btdmN'><pre id='btdmN'><center id='btdmN'></center></pre></bdo></b><th id='btdmN'></th></span></q></dt></tr></i><div id='btdmN'><tfoot id='btdmN'></tfoot><dl id='btdmN'><fieldset id='btdmN'></fieldset></dl></div>
                          <tbody id='btdmN'></tbody>

                          <legend id='btdmN'><style id='btdmN'><dir id='btdmN'><q id='btdmN'></q></dir></style></legend>
                            <bdo id='btdmN'></bdo><ul id='btdmN'></ul>

                          • <small id='btdmN'></small><noframes id='btdmN'>