如何在Laravel中删除表? [英] How to drop table in Laravel?

查看:745
本文介绍了如何在Laravel中删除表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我有此错误:

[PDOException]

[PDOException]

SQLSTATE [42S01]:基表或视图已存在:1050表'歌曲'已存在

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'songs' already exists

这是我的迁移文件:

<?php 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 
class CreateSongsTable extends Migration 
{
    public function up() 
    {
        Schema::create('songs', function (Blueprint $table) 
        {
            $table->increments('id');
            $table->integer('user_id');
            $table->string('title');
            $table->string('slug')->unique();
            $table->timestamps();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });
    }
}

我认为解决方案是删除表然后再次运行迁移,那么如何使用命令行在Laravel 5中删除表?我正在使用MySQL.

I think the solution will be just to delete the table then run migration again, so how can I drop a table in Laravel 5 using the command line? I am using MySQL.

推荐答案

我发现一个很好的简单方法就是使用phpmyadmin并手动删除表.当然,如果再次运行迁移时迁移仍然存在,则将再次创建表.

A nice easy way that I found is just using phpmyadmin and just drop the table manually. Of course if the migration is still there when you run the migration again the table will be created again.

这篇关于如何在Laravel中删除表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆