【问题标题】:php artisan make:migration not creaing new tablephp artisan make:迁移不创建新表
【发布时间】:2021-06-15 13:27:05
【问题描述】:

我的数据库中有一个名为 affilaite 的表。 但是当我尝试创建一个名为 product 的新表时,它给了我一个错误 php artisan make:migration create_product_table

PHP Fatal error:  Cannot declare class CreateAffiliateTable, because the name is already in use in /home/manak/Desktop/manu/Edolve/database/migrations/2021_03_09_063908_create_affiliate_table.php on line 7

   Symfony\Component\ErrorHandler\Error\FatalError 

  Cannot declare class CreateAffiliateTable, because the name is already in use

  at database/migrations/2021_03_09_063908_create_affiliate_table.php:7
      3▕ use Illuminate\Database\Migrations\Migration;
      4▕ use Illuminate\Database\Schema\Blueprint;
      5▕ use Illuminate\Support\Facades\Schema;
      6▕ 
  ➜   7▕ class CreateAffiliateTable extends Migration
      8▕ {
      9▕     
     10▕       Run the migrations.
     11▕      


   Whoops\Exception\ErrorException 

  Cannot declare class CreateAffiliateTable, because the name is already in use

  at database/migrations/2021_03_09_063908_create_affiliate_table.php:7
      3▕ use Illuminate\Database\Migrations\Migration;
      4▕ use Illuminate\Database\Schema\Blueprint;
      5▕ use Illuminate\Support\Facades\Schema;
      6▕ 
  ➜   7▕ class CreateAffiliateTable extends Migration
      8▕ {
      9▕     
     10▕       Run the migrations.
     11▕      

      +1 vendor frames 
  2   [internal]:0
      Whoops\Run::handleShutdown()

【问题讨论】:

  • 同名的类已经存在。为您的迁移使用其他名称或先删除旧名称。
  • 您的迁移是否已使用此类名称 CreateAffiliateTable 执行?可能是您在迁移中具有相同的类名。改个名字试试,也可以给CreateAffiliateV1Table

标签: php laravel migration laravel-artisan


【解决方案1】:

从这个错误我认为你已经有一个名为 CreateAffiliateTable 的迁移。

请更改您的迁移名称或删除旧迁移

【讨论】:

    【解决方案2】:

    检查您的数据库/迁移文件夹。如果一个文件已经存在那里删除它。此外,如果已经有一个名称完全相同的表,请从数据库中删除该表。在数据库中还有一个迁移表。也从那里删除表名,然后再次尝试迁移。 按照 laravel 约定,迁移是复数,模型名称是单数。所以最好尝试 CreateAffiliatesTable 而不是 CreateAffiliateTable

    【讨论】:

      【解决方案3】:

      使用这个命令创建 $ php artisan make:migration create_products_table

      【讨论】:

        猜你喜欢
        • 2015-03-28
        • 1970-01-01
        • 2016-07-29
        • 2014-02-16
        • 2014-08-20
        • 2015-05-05
        • 2019-06-30
        • 2020-01-18
        • 2018-06-07
        相关资源
        最近更新 更多