【问题标题】:call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\MySqlConnection' does not have a method ' query'call_user_func_array() 期望参数 1 是一个有效的回调,类 'Illuminate\Database\MySqlConnection' 没有方法 'query'
【发布时间】:2020-02-21 13:17:42
【问题描述】:

//迁移此文件时出现上述错误

<?php

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

class SubjectOrderForExam extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('subjectOrderingForExam', function(Blueprint $table)
        {
            $table->integer('id', true);
            $table->integer('subjectId');
            $table->integer('classId');
            $table->integer('sectionId');
            $table->string('subjectName', 255);
            $table->integer('orderingNo');
            $table->enum('isDelete', ['0','1'])->default('0');
        });
    }

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

}

【问题讨论】:

  • 您的代码与错误无关。你能把你的错误堆栈放在这里吗?
  • @KrisRoofe 原谅我吗?

标签: php laravel-4 command migration laravel-artisan


【解决方案1】:

也许您没有为此使用所有需要的命名空间。

例如,在我的 laravel 6 项目之一中,我在开头包含以下内容(注意 Schema ns):

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

【讨论】:

  • 我使用的是 laravel 4.2 版本。是否适用于 laravel 4.2?
  • 那是不同的。通过查看 Laravel 4.2 文档,您可能应该像这样创建您的架构(请注意,我没有使用蓝图): Schema::create('subjectOrderingForExam', function($table) ......也许你的“id”列应该是类型为“增量”而不是整数。$table->increments('id'); 尝试两者并告诉我们是否适合您。此外,最好在标题中指定您使用的 laravel 版本帖子:)。
猜你喜欢
  • 2014-06-14
  • 2013-08-01
  • 2012-10-04
  • 1970-01-01
  • 2016-06-06
  • 1970-01-01
  • 2021-04-18
  • 2015-10-18
  • 1970-01-01
相关资源
最近更新 更多