Php Laravel迁移dropColumn删除错误的列

Php Laravel迁移dropColumn删除错误的列,php,laravel,model,migration,rollback,Php,Laravel,Model,Migration,Rollback,我有一个很奇怪的问题,我无法解释。这让我非常担心,因为我正在做的项目是在线的,有时我可能会更新数据库列 现在我迁移了,一切都很好,我检查过了,我的表是好的 html(master)$ php artisan migrate Migrated: 2015_03_19_111236_change_user_profiles_table 这是我MySQL表的一部分 现在我回滚,尽管听起来很简单 html(master)$ php artisan migrate:rollback Rolled

我有一个很奇怪的问题,我无法解释。这让我非常担心,因为我正在做的项目是在线的,有时我可能会更新数据库列

现在我迁移了,一切都很好,我检查过了,我的表是好的

html(master)$ php artisan migrate
Migrated: 2015_03_19_111236_change_user_profiles_table
这是我MySQL表的一部分

现在我回滚,尽管听起来很简单

 html(master)$ php artisan migrate:rollback
 Rolled back: 2015_03_19_111236_change_user_profiles_table
现在我只是看着我的桌子,它变得很奇怪

是的,
状态
列无缘无故消失。还有一个应该被移除的。我试了10次都没用。。。我甚至不能再迁移了,因为

   [Illuminate\Database\QueryException]
   SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'status_
   updated_at' (SQL: alter table `user_profiles` add `status_updated_at` datet
   ime null)
有人对此有想法吗?如果这是一个问题,这是一个大问题,因为迁移在项目中是非常敏感的事情。。。我真的不再信任拉威尔了,我想知道我在制作方面会怎么做

**编辑:要在此处找到解决方案,请列出与此表链接的所有迁移(但无论如何都不应调用它…)

我用的是Laravel4.2**

后来


在一些迁移中,我和classe同名,这一事实给作曲家带来了麻烦。一个
composer dump autoload
允许我看到它

例如:

 Generating autoload files
 Warning: Ambiguous class resolution, "ChangeBoxQuestionsTable" was found in both      "/Users/Loschcode/Dropbox/htdocs/projets/bordeaux_in_box_lo/html/app/database/migrations/2015_03_12_183836_change_box_questions_table.php" and "/Users/Loschcode/Dropbox/htdocs/projets/bordeaux_in_box_lo/html/app/database/migrations/2015_03_19_040137_change_box_questions_table.php", the first will be used.

因此,我手动更改了文件/类的名称,也更改了数据库
migrations
表中的名称。现在它工作正常;)

有什么限制吗?外键约束?您使用的是哪个版本的laravel?您是否已使用composer进行了更新,从而获得了最新的错误修复?有一些限制,但它不应更改
状态
状态_updated_at
的任何内容,不是吗?它是
Laravel 4.2
,这个版本的composer大约有
5个月了(项目的开始),我非常害怕在我的服务器上更新它…你确定没有两个命名相同的类吗?从我所看到的
ChangeUserProfilesTable
用于两次迁移。因此,在
rollback
上调用的实际迁移似乎是创建了
status
字段的迁移。尝试在此迁移中使用
dd
回滚方法,并检查是否是这样。顺便说一句,您应该会得到一个关于
ChangeUserProfilesTable
模棱两可的错误。如果没有,则可能是您的配置正在抑制此消息。如果自动加载未找到该类,则他正在尝试回滚该表的其他版本。也许做
comoser dump autoload
可以结合上面的评论帮助您?这是一种很有趣的行为。但是
composer dump autoload
应该检测到在同一命名空间中有两个同名的类,并让您知道这一点。无论如何,在将来,我会建议为您的迁移使用更具描述性的名称,比如
更新\用户\配置文件\表格\添加\状态\列
等等。这样,您就可以非常确定您的迁移名称不会与任何其他名称冲突。
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserProfilesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_profiles', function($table)
        {

            // Keys
            $table->increments('id');
            $table->integer('user_id')->unsigned()->nullable();
            $table->integer('box_id')->unsigned()->nullable();

            $table->string('stripe_customer');

            $table->string('contract_id');

            // Indexes
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('box_id')->references('id')->on('boxes')->onDelete('cascade');

            // Timestamps
            $table->timestamps();
            $table->softDeletes();

        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

        Schema::table('user_profiles', function(Blueprint $table)
        {

            $table->dropForeign('user_profiles_user_id_foreign');
            $table->dropForeign('user_profiles_box_id_foreign');

        });

        Schema::dropIfExists('user_profiles');

    }


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

class ChangeUserProfilesTable extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('user_profiles', function($table)
        {

            // Keys
            $table->enum('status', array('not-subscribed', 'in-progress', 'subscribed', 'expired'));

        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {

        Schema::table('user_profiles', function(Blueprint $table)
        {

            // Columns to remove
            $table->dropColumn('status');

        });


    }

}
 Generating autoload files
 Warning: Ambiguous class resolution, "ChangeBoxQuestionsTable" was found in both      "/Users/Loschcode/Dropbox/htdocs/projets/bordeaux_in_box_lo/html/app/database/migrations/2015_03_12_183836_change_box_questions_table.php" and "/Users/Loschcode/Dropbox/htdocs/projets/bordeaux_in_box_lo/html/app/database/migrations/2015_03_19_040137_change_box_questions_table.php", the first will be used.