PHP artisan migrate不创建迁移表

56lgkhnf  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(113)

我已经设置好了我的laravel项目,配置了mysql用户名和密码,并创建了数据库。我已经设置好了迁移和种子。然而,当我运行php artisan migrate时,我遇到了以下错误。

INFO  Preparing database.  

  Creating migration table ............................................................................................................... 38ms DONE

   INFO  Loading stored database schemas.  

  database/schema/mysql-schema.sql ...................................................................................................... 115ms DONE

In Connection.php line 801:
                                                                                                                                                                                                        
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_name.migrations' doesn't exist (Connection: mysql, SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)  
                                                                                                                                                                                                        

In Connection.php line 416:
                                                                                                   
  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_name.migrations' doesn't exist

字符串
我尝试在MySQL中创建迁移表,

USE db_name; CREATE TABLE migrations (     id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,     migration VARCHAR(255) NOT NULL,     batch INT NOT NULL ) ENGINE=InnoDB;


然后它返回Query OK, 0 rows affected (0.01 sec)。然而,当我使用php artisan migrate运行迁移时,我遇到了上面提到的相同错误,当我查看数据库时,迁移表不再存在。
问题可能是什么,我该如何解决它?

qyuhtwio

qyuhtwio1#

试试这个:

app/Providers/AppServiceProvider.php:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;  # Added this Line

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Schema::defaultStringLength(191);  # Added this Line
    }
}

字符串
来源:Laravel migration is not working and missing migrations table

相关问题