Laravel Can';t在拉拉维尔运行迁移

Laravel Can';t在拉拉维尔运行迁移,laravel,Laravel,这是否也发生在其他人身上。我创建了一个站点,在某个时候我的迁移不想再运行了。Laravel正在检索表不存在的错误,然后我运行了php artisan migration:reset,并手动从数据库中删除了所有表,但再次显示了相同的错误 错误 Base table or view not found: 1146 Table 'db_blogtech.settings' doesn't exist 这就是迁移: public function up() { Schema::create('

这是否也发生在其他人身上。我创建了一个站点,在某个时候我的迁移不想再运行了。Laravel正在检索表不存在的错误,然后我运行了
php artisan migration:reset
,并手动从数据库中删除了所有表,但再次显示了相同的错误

错误

Base table or view not found: 1146 Table 'db_blogtech.settings' doesn't exist
这就是迁移:

public function up()
{
    Schema::create('settings', function (Blueprint $table) {
        $table->id();
        $table->string('site_name')->default("Digy Studio");
        $table->text('site_description')->nullable();
        $table->string('site_facebook')->nullable();
        $table->string('site_instagram')->nullable();
        $table->string('site_twitter')->nullable();
        $table->string('site_linkedin')->nullable();
        $table->string('site_behance')->nullable();
        $table->string('site_dribbble')->nullable();
        $table->string('site_email')->nullable();
        $table->string('site_field_one')->nullable();
        $table->string('site_field_one_value')->nullable();
        $table->string('site_field_two')->nullable();
        $table->string('site_field_two_value')->nullable();
        $table->string('site_field_three')->nullable();
        $table->string('site_field_three_value')->nullable();
        $table->string('site_field_four')->nullable();
        $table->string('site_field_four_value')->nullable();
        $table->string('site_copyright')->nullable();
        $table->string('site_creator_name')->nullable();
        $table->string('site_creator_link')->nullable();
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('settings');
}
编辑,因为问题是AppServiceProvider中使用了设置模型,这里是代码的一部分。我在这里向所有视图共享它,所以我在所有视图中都需要它,并且我试图避免在代码中重复我自己。如果有其他解决方案,请写在评论中,或者如果有人知道如何将其放入
尝试catch

以下是代码的一部分:

public function boot()
    {
        View::share('settings', Setting::firstOrFaiL());
    }

不鼓励在服务提供商中使用数据库。这是因为并非所有请求都需要数据库连接或(在您的情况下)呈现视图,这意味着您正在连接到数据库,而不需要潜在地进行访问

对于您的特定用例,我建议使用视图生成器,例如,在您的提供程序中添加以下内容:

View::composer('*', function ($view) {
    if (!View::shared('settings')) {
       View::share('settings', Setting::firstOrFaiL());
    }
});
这样,在实际合成任何视图之前,都不会读取设置

如果您坚持直接在提供程序中使用此选项,则可以确保它仅在web请求中运行:

public function boot()
{
    if (!app()->runningInConsole() && !app()->runningUnitTests()) {
        View::share('settings', Setting::firstOrFaiL());
    }
}


这篇文章对你有帮助吗?如果您删除了所有内容,请尝试
migrate:fresh
@apokryfos-tryed无助于检查迁移的运行顺序。在创建设置表之前,请确保没有任何内容使用设置表。如果有什么东西使用了桌子,可能值得移动它。迁移按字母顺序运行,因此您可以重命名迁移文件以控制首先运行的内容从您共享的错误开始,您似乎正在使用某个提供程序中的设置表。这是一种鸡和蛋的问题。如果不启动应用程序,则无法运行迁移,但如果设置表不存在,则无法启动应用程序。如果确实是这样,我会将设置的获取包装在
try。。。捕获
,并返回到一些默认值,以防该表不存在。这很好,但正如您所说的,如果这不是一个好的做法,是否有更好的方法?在需要设置的所有控制器中手动重复这部分代码是否更好?我对laravel还比较陌生,正在尝试学习一些更高级的功能:)理想的方法是使用视图生成器,但只包括需要设置的视图名称。您只需放置一个数组,而不是视图名称的
“*”
,例如
['layouts.index',…]
就我个人而言,我有一个主视图,我的所有其他视图都继承自该视图,我的视图生成器负责传递所有视图都应该传递的数据。我只是想问您,如果我有一个主视图,所有其他视图都从中扩展到只放一个主视图,那么其他视图是否可以工作:D您帮了我很多,谢谢!我现在得到这个错误
未定义变量:设置(视图:C:\xampp\htdocs\…\resources\views\index.blade.php)
。我已将您发送的部分代码放在注释中,$settings用于
布局中。主视图
(所有其他视图都从中继承,包括索引)