【问题标题】:Laravel migration [ErrorException] Undefined index: index_typeLaravel 迁移 [ErrorException] 未定义索引:index_type
【发布时间】:2016-11-14 15:24:15
【问题描述】:

我正在尝试迁移我的 laravel 项目。

但是当我输入迁移命令时,我收到了这个错误。我不明白为什么当我尝试迁移我的项目时它给我这个错误。

[ErrorException]             
  Undefined index: index_type  



Exception trace:
 () at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php:75
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php:75
 Doctrine\DBAL\Schema\MySqlSchemaManager->_getPortableTableIndexesList() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:193
 Doctrine\DBAL\Schema\AbstractSchemaManager->listTableIndexes() at /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:286
 Doctrine\DBAL\Schema\AbstractSchemaManager->listTableDetails() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/Grammar.php:320
 Illuminate\Database\Schema\Grammars\Grammar->getChangedDiff() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/Grammar.php:302
 Illuminate\Database\Schema\Grammars\Grammar->compileChange() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:107
 Illuminate\Database\Schema\Blueprint->toSql() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php:82
 Illuminate\Database\Schema\Blueprint->build() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:229
 Illuminate\Database\Schema\Builder->build() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php:130
 Illuminate\Database\Schema\Builder->table() at /var/www/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:237
 Illuminate\Support\Facades\Facade::__callStatic() at /var/www/database/migrations/2016_10_25_222438_update_relationships_for_employee.php:20
 Illuminate\Support\Facades\Schema::table() at /var/www/database/migrations/2016_10_25_222438_update_relationships_for_employee.php:20
 UpdateRelationshipsForEmployee->up() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:373
 Illuminate\Database\Migrations\Migrator->Illuminate\Database\Migrations\{closure}() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:380
 Illuminate\Database\Migrations\Migrator->runMigration() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:162
 Illuminate\Database\Migrations\Migrator->runUp() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:130
 Illuminate\Database\Migrations\Migrator->runMigrationList() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php:97
 Illuminate\Database\Migrations\Migrator->run() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/MigrateCommand.php:66
 Illuminate\Database\Console\Migrations\MigrateCommand->fire() at n/a:n/a
 call_user_func_array() at /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php:508
 Illuminate\Container\Container->call() at /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
 Illuminate\Console\Command->execute() at /var/www/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
 Illuminate\Console\Command->run() at /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:185
 Illuminate\Console\Command->call() at /var/www/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/RefreshCommand.php:66
 Illuminate\Database\Console\Migrations\RefreshCommand->fire() at n/a:n/a
 call_user_func_array() at /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php:508
 Illuminate\Container\Container->call() at /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:169
 Illuminate\Console\Command->execute() at /var/www/vendor/symfony/console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php:155
 Illuminate\Console\Command->run() at /var/www/vendor/symfony/console/Application.php:820
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/console/Application.php:187
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/console/Application.php:118
 Symfony\Component\Console\Application->run() at /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:121
 Illuminate\Foundation\Console\Kernel->handle() at /var/www/artisan:36

我的迁移文件在下面。

<?php

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

class UpdateRelationshipsForEmployee extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        Schema::table('employee',function ($table){
            $table->integer('retail_id')->unsigned()->index()->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('employee', function ($table){
            $table->integer('retail_id')->change();
        });
        //

    }
}

【问题讨论】:

  • 显示来自/var/www/database/migrations/2016_10_25_222438_update_relationships_for_employee.php的代码
  • @aynber 我刚刚将我的代码添加到帖子中。
  • 尝试在单独的行上添加索引。 $table-&gt;index('retail_id');
  • 当您收到artisan 错误时,该错误可能与当前尝试使用artisan 运行的命令无关,但与您最近犯的任何其他编码错误有关。在您的代码中搜索最近对 index_type 的引用。 Ref
  • 我已经搜索过,但我没有对 index_type 的引用

标签: php laravel laravel-5 migration


【解决方案1】:

只需删除整个数据库并运行命令 php artisan migrate:refresh --seed

您还可以维护您的数据库。 只需复制您的模型和迁移信息。 然后删除。 删除后重新创建模型和表。

现在。转到您的数据库迁移表。删除员工行。 现在。删除您的员工表。

现在只需终端命令 php artisan migrate

【讨论】:

  • 是的,只需删除数据库和php artisan migrate
【解决方案2】:

检查您的操作系统语言环境或 php 语言环境,

无法在 laravel 使用的依赖库中正确转换大写,因为您的语言环境与 en_us.UTF8 不同

试试

setlocale(LC_CTYPE, 'en_US.UTF8');

使用 en_us.UTF8 进行大小写转换,无论活动区域设置如何。

【讨论】:

    猜你喜欢
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 2021-02-13
    • 1970-01-01
    • 2021-08-22
    • 2021-07-06
    • 1970-01-01
    相关资源
    最近更新 更多