首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel Migrations -列已经存在

Laravel Migrations -列已经存在
EN

Stack Overflow用户
提问于 2017-02-19 21:36:45
回答 1查看 5.2K关注 0票数 2

我正在运行Laravel Framework version 5.2.45,并希望迁移我的数据库。

我有两次迁徙。一个是从盒子里出来的标准2014_10_12_100000_create_password_resets_table,另一个是我新创建的迁移2017_02_19_172350_create_keywords_table

代码语言:javascript
复制
<?php

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

class CreateKeywordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('keywords', function (Blueprint $table) {
            $table->increments('id');
            $table->string('keyword');
            $table->timestamps();
            $table->timestamps('published_at');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('keywords');
    }
}

执行我得到的典型php artisan migrate (在回滚之前):

代码语言:javascript
复制
root:~/workspace $ php artisan migrate:rollback
Rolled back: 2014_10_12_100000_create_password_resets_table
root:~/workspace $ php artisan migrate


  [Illuminate\Database\QueryException]                                                                                                                 
  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' (SQL: create table `keywords` (`id` int unsigned not null auto_incr  
  ement primary key, `keyword` varchar(255) not null, `created_at` timestamp null, `updated_at` timestamp null, `created_at` timestamp null, `updated  
  _at` timestamp null) default character set utf8 collate utf8_unicode_ci)                                                                             



  [PDOException]                                                                   
  SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at'  


root:~/workspace $ 

在数据库中,没有创建表keywords

有什么建议我做错了吗?

谢谢你的回复!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-19 21:42:33

$table->timestamps();是一个函数,它总是会添加created_atupdated_at字段。在您的例子中,您要添加这两次。

如果要添加另一个时间戳字段,则必须使用timestamp()函数。

因此,您应该将published_at的行替换为以下内容(删除s):

代码语言:javascript
复制
$table->timestamp('published_at');

文献资料中可以找到所有可能的列类型的列表。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42333195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档