首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel迁移找不到表

Laravel迁移找不到表
EN

Stack Overflow用户
提问于 2016-09-08 15:18:58
回答 2查看 634关注 0票数 0

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

代码语言:javascript
复制
  [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)  

我已经重启了我的服务器。这是工单迁移:

代码语言:javascript
复制
<?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');
    }
}

这里会有什么问题呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-08 15:33:36

更改:

代码语言:javascript
复制
Schema::table('ticket', function (Blueprint $table){

进入:

代码语言:javascript
复制
Schema::create('ticket', function (Blueprint $table){

并在控制台中使用composer dump-autoload。希望这会有帮助=)

票数 1
EN

Stack Overflow用户

发布于 2016-09-08 15:35:01

尝试将创建与foreing key alter语句分开

代码语言:javascript
复制
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');
        });
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39384781

复制
相关文章

相似问题

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