You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel Voyager创建表时未生成迁移文件的解决方案求助

Solutions for Generating Migration Files After Creating Tables with Voyager's Database Manager

Got it, I've run into this exact issue with Voyager's Database Manager before—super frustrating when you need to keep your team's DB schemas in sync via Git. Here are a few solid solutions to fix this:

1. Generate Migrations from Existing Tables (Quick Retroactive Fix)

If you've already created tables via Voyager and need to catch up on migration files, use a dedicated Laravel package to scan your database and build migrations automatically:

  • Install the migration generator package via Composer:
    composer require kitloong/laravel-migrations-generator --dev
    
  • Run the command to generate migrations for specific tables (replace your_table_name with your actual table name; omit the table name to generate migrations for all tables):
    php artisan migrate:generate your_table_name
    
  • This will create fully structured migration files in database/migrations that match your Voyager-created table schemas. Commit these files to Git, and your team can run php artisan migrate to sync their local databases instantly.

2. Modify Voyager to Auto-Generate Migrations (Permanent Fix)

If you want Voyager's Database Manager to create migrations automatically every time you add or modify tables, you can extend its core logic (avoid editing vendor files directly—create an override instead):

  • Create a custom controller that extends Voyager's DatabaseController, then override the addTable method
  • After the table is created successfully, add code to generate a migration file programmatically using Laravel's MigrationCreator class:
    use Illuminate\Database\Migrations\MigrationCreator;
    use Illuminate\Support\Facades\App;
    
    // Insert this after the table creation logic
    $creator = App::make(MigrationCreator::class);
    $migrationName = 'create_' . $request->input('name') . '_table';
    $creator->create($migrationName, database_path('migrations'));
    
    // You'll also need to populate the migration file with column definitions
    // Extract the column data from the request used to create the table
    
  • Update your routes to point to this custom controller instead of the default Voyager one. Now every table created via Voyager will have a matching migration file.

3. Shift to a Migration-First Workflow (Long-Term Best Practice)

For smoother team collaboration, align with Laravel's native workflow:

  • First write a migration file using php artisan make:migration create_your_table_name_table
  • Define your table schema in the migration's up method, then run php artisan migrate to create the table
  • Use Voyager's UI only for managing data, editing field details, or setting up BREAD (Browse, Read, Edit, Add, Delete) functionality
  • This ensures migrations are always the single source of truth for your database schema, making Git-based syncing straightforward for your entire team

内容的提问来源于stack exchange,提问作者Lohith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:54:12