gpt4 book ai didi

laravel-4 - 使用 Laravel 种子和 sql 文件填充数据库

转载 作者:行者123 更新时间:2023-12-03 21:00:56 25 4
gpt4 key购买 nike

我从 github 得到了几个国家、州和城市的 .sql 文件。我如何使用 Laravel 的种子文件运行它们来填充我的数据库中的这些表?

最佳答案

  • 添加 DB::unprepared()DatabaseSeeder的run方法.
  • 运行 php artisan db:seed在命令行。
    class DatabaseSeeder extends Seeder {

    public function run()
    {
    Eloquent::unguard();

    $this->call('UserTableSeeder');
    $this->command->info('User table seeded!');

    $path = 'app/developer_docs/countries.sql';
    DB::unprepared(file_get_contents($path));
    $this->command->info('Country table seeded!');
    }
    }
  • 关于laravel-4 - 使用 Laravel 种子和 sql 文件填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37369452/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com