【问题标题】:BadMethodCallException || Method Illuminate\Database\Schema\Blueprint::after does not exist坏方法调用异常 ||方法 Illuminate\Database\Schema\Blueprint::after 不存在
【发布时间】:2021-12-30 10:19:24
【问题描述】:

BadMethodCallException ... 方法 Illuminate\Database\Schema\Blueprint::after 不存在。 我无法为我的项目迁移我的数据库...这是我面临的错误

.................................................. .........................

cmd 错误,(我迁移失败):

E:\xampp\htdocs\face_clone1>php artisan migrate
Migrating: 2021_11_19_104856_update_users_table

   BadMethodCallException

  Method Illuminate\Database\Schema\Blueprint::after does not exist.

  at E:\xampp\htdocs\face_clone1\vendor\laravel\framework\src\Illuminate\Support\Traits\Macroable.php:103
     99|      */
    100|     public function __call($method, $parameters)
    101|     {
    102|         if (! static::hasMacro($method)) {
  > 103|             throw new BadMethodCallException(sprintf(
    104|                 'Method %s::%s does not exist.', static::class, $method
    105|             ));
    106|         }
    107|

  • Bad Method Call: Did you mean Illuminate\Database\Schema\Blueprint::date() ?

  1   E:\xampp\htdocs\face_clone1\database\migrations\2021_11_19_104856_update_users_table.php:23
      Illuminate\Database\Schema\Blueprint::__call("after")

  2   E:\xampp\htdocs\face_clone1\vendor\laravel\framework\src\Illuminate\Database\Schema\Blueprint.php:88
      UpdateUsersTable::{closure}(Object(Illuminate\Database\Schema\Blueprint))

E:\xampp\htdocs\face_clone1>

我的代码在这里:

    <?php
        
        use Illuminate\Database\Migrations\Migration;
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Support\Facades\Schema;
        
        class UpdateUsersTable extends Migration {
            /**
             * Run the migrations.
             *
             * @return void
             */
            public function up()
            {
                  Schema::table('users', function (Blueprint $table){
                    $table->after('name', function ($table){
                       $table->renameColumn('name', 'fname');
                       $table->string('lname');
                       $table->boolean('sex');
                       $table->date('b_day')->default('2021-01-01');
                       $table->string('image');
                    });
                });
            }
        
            /**
             * Reverse the migrations.
             *
             * @return void
             */
            public function down()
            {
                //
            } 
      }
    

【问题讨论】:

  • 你使用的是什么版本的 Laravel?
  • afteradded in 8.27,因此请确保您至少使用该版本。
  • laravel 版本 ^7.29
  • 你也可以使用 AFTER 作为 raw

标签: php sql laravel migration


【解决方案1】:

已解决::: 谢谢bhucho [https://stackoverflow.com/users/9471283/bhucho]

<?php
    
    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    use Illuminate\Support\Facades\Schema;
    
    class UpdateUsersTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
              Schema::table('users', function (Blueprint $table){
                $table->renameColumn('name', 'fname');
                   $table->string('lname')->after('email');
                   $table->boolean('sex')->after('email');
                   $table->date('b_day')->default('2021-01-01')->after('email');
                   $table->string('image')->after('email');
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            //
        }
    }

【讨论】:

    猜你喜欢
    • 2022-12-21
    • 2021-04-12
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    • 2020-11-21
    • 2018-09-24
    相关资源
    最近更新 更多