【问题标题】:Laravel migration cannot find tableLaravel 迁移找不到表
【发布时间】:2017-01-16 00:33:11
【问题描述】:

我遇到了一个非常奇怪的问题。当我尝试迁移我的迁移时,我收到错误:

  [Illuminate\Database\QueryException]                                         
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cforum.ticket' d  
  oesn't exist (SQL: alter table `ticket` add `id` int unsigned not null auto  
  _increment primary key, add `title` varchar(255) not null, add `description  
  ` varchar(255) not null, add `user_id` int unsigned not null, add `subject_  
  id` int unsigned not null, add `status_id` int unsigned not null)  

我已经重新启动了我的服务器。这是票证迁移:

<?php

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

class CreateTicketTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('ticket', function (Blueprint $table) {

            $table->increments('id');
            $table->string('title');
            $table->string('description');

            $table->integer('user_id')->unsigned();
            $table->foreign('user_id')
                ->references('id')->on('user')
                ->onDelete('cascade');

            $table->integer('subject_id')->unsigned();
            $table->foreign('subject_id')
                ->references('id')->on('subject')
                ->onDelete('cascade');

            $table->integer('status_id')->unsigned();
            $table->foreign('status_id')
                ->references('id')->on('status')
                ->onDelete('cascade');
        });
    }

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

这里有什么问题?

【问题讨论】:

    标签: php laravel migration database-migration


    【解决方案1】:

    变化:

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

    进入:

    Schema::create('ticket', function (Blueprint $table){
    

    并在您的控制台中使用composer dump-autoload。希望对你有帮助=)

    【讨论】:

    • 谢谢你是英雄!
    【解决方案2】:

    尝试将创建与这样的外键更改语句分开

    public function up()
        {
            Schema::create('ticket', function (Blueprint $table) {
                $table->increments('id');
                $table->string('title');
                $table->string('description');
                $table->integer('user_id')->unsigned();
                $table->integer('subject_id')->unsigned();
                $table->integer('status_id')->unsigned();     
            }
            Schema::table('ticket', function (Blueprint $table) {
    
                $table->foreign('user_id')
                    ->references('id')->on('user')
                    ->onDelete('cascade');
    
                $table->foreign('subject_id')
                    ->references('id')->on('subject')
                    ->onDelete('cascade');
    
                $table->foreign('status_id')
                    ->references('id')->on('status')
                    ->onDelete('cascade');
            });
        }
    

    【讨论】:

      猜你喜欢
      • 2021-11-07
      • 2014-02-28
      • 2012-12-13
      • 2013-10-16
      • 2021-02-19
      • 2021-09-24
      • 1970-01-01
      • 2019-02-07
      • 2015-08-29
      相关资源
      最近更新 更多