Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel/Lumen表名不正确'';对于迁移表SQLSTATE[42000]_Laravel_Vagrant_Lumen_Artisan Migrate - Fatal编程技术网

Laravel/Lumen表名不正确'';对于迁移表SQLSTATE[42000]

Laravel/Lumen表名不正确'';对于迁移表SQLSTATE[42000],laravel,vagrant,lumen,artisan-migrate,Laravel,Vagrant,Lumen,Artisan Migrate,运行php artisan migrate时,当它试图在mysql中创建迁移表时,我收到一个错误: In Connection.php line 664: SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`id` int u nsigned not null auto_increment primary key, `migra

运行
php artisan migrate
时,当它试图在mysql中创建迁移表时,我收到一个错误:

In Connection.php line 664:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`id` int u  
  nsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default cha  
  racter set utf8 collate 'utf8_unicode_ci')                                                                         


In Connection.php line 452:

  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''  
以下是完整的错误日志:

In Connection.php line 664:

  [Illuminate\Database\QueryException (42000)]                                                                       
  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name '' (SQL: create table `` (`id` int u  
  nsigned not null auto_increment primary key, `migration` varchar(255) not null, `batch` int not null) default cha  
  racter set utf8 collate 'utf8_unicode_ci')                                                                         


Exception trace:
 () at /home/vagrant/api/vendor/illuminate/database/Connection.php:664
 Illuminate\Database\Connection->runQueryCallback() at /home/vagrant/api/vendor/illuminate/database/Connection.php:624
 Illuminate\Database\Connection->run() at /home/vagrant/api/vendor/illuminate/database/Connection.php:459
 Illuminate\Database\Connection->statement() at /home/vagrant/api/vendor/illuminate/database/Schema/Blueprint.php:97
 Illuminate\Database\Schema\Blueprint->build() at /home/vagrant/api/vendor/illuminate/database/Schema/Builder.php:278
 Illuminate\Database\Schema\Builder->build() at /home/vagrant/api/vendor/illuminate/database/Schema/Builder.php:167
 Illuminate\Database\Schema\Builder->create() at /home/vagrant/api/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php:157
 Illuminate\Database\Migrations\DatabaseMigrationRepository->createRepository() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/InstallCommand.php:54
 Illuminate\Database\Console\Migrations\InstallCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at /home/vagrant/api/vendor/illuminate/container/Container.php:576
 Illuminate\Container\Container->call() at /home/vagrant/api/vendor/illuminate/console/Command.php:183
 Illuminate\Console\Command->execute() at /home/vagrant/api/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:170
 Illuminate\Console\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:198
 Illuminate\Console\Command->call() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:93
 Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:63
 Illuminate\Database\Console\Migrations\MigrateCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at /home/vagrant/api/vendor/illuminate/container/Container.php:576
 Illuminate\Container\Container->call() at /home/vagrant/api/vendor/illuminate/console/Command.php:183
 Illuminate\Console\Command->execute() at /home/vagrant/api/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:170
 Illuminate\Console\Command->run() at /home/vagrant/api/vendor/symfony/console/Application.php:921
 Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/api/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /home/vagrant/api/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /home/vagrant/api/vendor/illuminate/console/Application.php:90
 Illuminate\Console\Application->run() at /home/vagrant/api/vendor/laravel/lumen-framework/src/Console/Kernel.php:115
 Laravel\Lumen\Console\Kernel->handle() at /home/vagrant/api/artisan:35

In Connection.php line 452:

  [PDOException (42000)]                                                           
  SQLSTATE[42000]: Syntax error or access violation: 1103 Incorrect table name ''  


Exception trace:
 () at /home/vagrant/api/vendor/illuminate/database/Connection.php:452
 PDO->prepare() at /home/vagrant/api/vendor/illuminate/database/Connection.php:452
 Illuminate\Database\Connection->Illuminate\Database\{closure}() at /home/vagrant/api/vendor/illuminate/database/Connection.php:657
 Illuminate\Database\Connection->runQueryCallback() at /home/vagrant/api/vendor/illuminate/database/Connection.php:624
 Illuminate\Database\Connection->run() at /home/vagrant/api/vendor/illuminate/database/Connection.php:459
 Illuminate\Database\Connection->statement() at /home/vagrant/api/vendor/illuminate/database/Schema/Blueprint.php:97
 Illuminate\Database\Schema\Blueprint->build() at /home/vagrant/api/vendor/illuminate/database/Schema/Builder.php:278
 Illuminate\Database\Schema\Builder->build() at /home/vagrant/api/vendor/illuminate/database/Schema/Builder.php:167
 Illuminate\Database\Schema\Builder->create() at /home/vagrant/api/vendor/illuminate/database/Migrations/DatabaseMigrationRepository.php:157
 Illuminate\Database\Migrations\DatabaseMigrationRepository->createRepository() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/InstallCommand.php:54
 Illuminate\Database\Console\Migrations\InstallCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at /home/vagrant/api/vendor/illuminate/container/Container.php:576
 Illuminate\Container\Container->call() at /home/vagrant/api/vendor/illuminate/console/Command.php:183
 Illuminate\Console\Command->execute() at /home/vagrant/api/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:170
 Illuminate\Console\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:198
 Illuminate\Console\Command->call() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:93
 Illuminate\Database\Console\Migrations\MigrateCommand->prepareDatabase() at /home/vagrant/api/vendor/illuminate/database/Console/Migrations/MigrateCommand.php:63
 Illuminate\Database\Console\Migrations\MigrateCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:32
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:90
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/api/vendor/illuminate/container/BoundMethod.php:34
 Illuminate\Container\BoundMethod::call() at /home/vagrant/api/vendor/illuminate/container/Container.php:576
 Illuminate\Container\Container->call() at /home/vagrant/api/vendor/illuminate/console/Command.php:183
 Illuminate\Console\Command->execute() at /home/vagrant/api/vendor/symfony/console/Command/Command.php:255
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/api/vendor/illuminate/console/Command.php:170
 Illuminate\Console\Command->run() at /home/vagrant/api/vendor/symfony/console/Application.php:921
 Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/api/vendor/symfony/console/Application.php:273
 Symfony\Component\Console\Application->doRun() at /home/vagrant/api/vendor/symfony/console/Application.php:149
 Symfony\Component\Console\Application->run() at /home/vagrant/api/vendor/illuminate/console/Application.php:90
 Illuminate\Console\Application->run() at /home/vagrant/api/vendor/laravel/lumen-framework/src/Console/Kernel.php:115
 Laravel\Lumen\Console\Kernel->handle() at /home/vagrant/api/artisan:35
我尝试过销毁和重建vagrant实例,并删除和重新安装了composer软件包,但问题依然存在

根据要求,迁移文件:

    <?php

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

    class CreateTeachersTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('teachers', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->string('address');
                $table->string('phone');
                $table->string('profession');
                $table->timestamps();
            });
        }

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

    <?php

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

    class CreateStudentsTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('students', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->string('address');
                $table->string('phone');
                $table->string('career');
                $table->timestamps();
            });
        }

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

<?php

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

class CreateCoursesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('courses', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->text('description');
            $table->integer('value')->unsigned();
            $table->bigInteger('teacher_id')->unsigned();
            $table->foreign('teacher_id')->references('id')->on('teachers');
            $table->timestamps();
        });

    }

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

<?php

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

class CreateCourseStudentTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('course_student', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('course_id')->unsigned();
            $table->foreign('course_id')->references('id')->on('courses');
            $table->bigInteger('student_id')->unsigned();
            $table->foreign('student_id')->references('id')->on('students');
        });
    }

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

<?php

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

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('role_id');
            $table->string('email')->unique();
            $table->string('first_name');
            $table->string('last_name');
            $table->string('password');
            $table->tinyInteger('status')->default(1);
            $table->tinyInteger('master')->default(0);
            $table->softDeletes();
            $table->timestamps();
        });
    }

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

<?php

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

class CreateSystemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('systems', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->tinyInteger('status');
            $table->timestamps();
        });
    }

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

<?php

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

class CreateUserRolesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_roles', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->bigInteger('system_id');
        });
    }

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

<?php

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

class CreateUserRolePermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_role_permissions', function (Blueprint $table) {
            $table->bigInteger('user_role_id');
            $table->bigInteger('permission_id');
        });
    }

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

<?php

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

class CreateUserRolePermissionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_role_permissions', function (Blueprint $table) {
            $table->bigInteger('user_role_id');
            $table->bigInteger('permission_id');
        });
    }

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

<?php

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

class CreateLeadTypesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('lead_types', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('branch_id');
            $table->string('name');
            $table->string('token')->nullable();
            $table->softDeletes();
            $table->timestamps();
        });
    }

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

<?php

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

class CreateLeadStatusesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('lead_statuses', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('branch_id');
            $table->string('name');
            $table->softDeletes();
            $table->timestamps();
        });
    }

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

<?php

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

class CreateLeadsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('leads', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('lead_type_id');
            $table->bigInteger('status_id');
            $table->bigInteger('owner_id');
            $table->string('description');
            $table->softDeletes();
            $table->timestamps();
        });
    }

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

经过多次尝试和错误,我发现问题出在config/database.php文件中。我必须添加一个migrations变量(“migrations”=>“migrations”)

因此:

<?php
return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
        ],
        'mongodb' => [
            'driver' => 'mongodb',
            'host' => env('MONGODB_HOST'),
            'port' => env('MONGODB_PORT'),
            'database' => env('MONGODB_DATABASE'),
            'username' => env('MONGODB_USERNAME'),
            'password' => env('MONGODB_PASSWORD'),
            'options' => [
                'database' => 'admin'
            ]
        ],
    ]
];

将“migrations”=>“migrations”添加到database.php它将起作用

请发布您的迁移代码提供
迁移
文件创建迁移文件时是否使用artisan命令?尝试使用php artisan make:migration migration\u NAME_HERE--table=TABLENAME这将在迁移中为您指定表名。您是否在
config/database.php
中更改了任何内容?我在上面添加了迁移文件和config/database.php文件,您知道如何在lumen上执行此操作吗?@iamjc015此文件位于
config/
文件夹中:
config/database.php
。但是,只有在手动创建Lumen时,它才会出现在Lumen中,例如,当您需要添加第二个数据库连接时。我创建了我的数据库,添加了到另一个数据库的第二个连接,但我得到的示例也没有指定“migrations”属性,所以我出现了错误,这个答案为我解决了这个问题。谢谢:)@Paul您是如何发现这个问题的?如果数据库是在config中配置的,那么这是能够使用PHP-artisan-migrate命令的正确答案。
APP_NAME=APP
APP_ENV=local
APP_KEY=ka0mdHChmnMoQzSqWle7Zez
APP_DEBUG=true
APP_URL=http://localhost
APP_TIMEZONE=UTC

LOG_CHANNEL=stack
LOG_SLACK_WEBHOOK_URL=

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

CACHE_DRIVER=file
QUEUE_CONNECTION=sync

JWT_SECRET=VJXaIerVvIMXAF7w0Tt6FsMU8
<?php
return [
    'default' => 'mysql',
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
        ],
        'mongodb' => [
            'driver' => 'mongodb',
            'host' => env('MONGODB_HOST'),
            'port' => env('MONGODB_PORT'),
            'database' => env('MONGODB_DATABASE'),
            'username' => env('MONGODB_USERNAME'),
            'password' => env('MONGODB_PASSWORD'),
            'options' => [
                'database' => 'admin'
            ]
        ],
    ]
];
<?php
return [
    'default' => 'mysql',
    'migrations' => 'migrations',
    'connections' => [
        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST'),
            'database' => env('DB_DATABASE'),
            'username' => env('DB_USERNAME'),
            'password' => env('DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
        ],
        'mongodb' => [
            'driver' => 'mongodb',
            'host' => env('MONGODB_HOST'),
            'port' => env('MONGODB_PORT'),
            'database' => env('MONGODB_DATABASE'),
            'username' => env('MONGODB_USERNAME'),
            'password' => env('MONGODB_PASSWORD'),
            'options' => [
                'database' => 'admin'
            ]
        ],
    ]
];