【问题标题】:Laravel 5.3 Parse error: syntax error, unexpected '$table' (T_VARIABLE) when migratingLaravel 5.3 解析错误:语法错误,迁移时出现意外的 '$table' (T_VARIABLE)
【发布时间】:2017-06-04 22:48:34
【问题描述】:

这是我的迁移代码:

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
          Schema::create('orders', function (Blueprint $table){
          $table->increments('order_id');
          $table->integer('order_no');
          $table->string('total_price');
          $table->date('date_received');
          $table->date('date_expected');
          $table->integer('product_id')->unsigned();
          $table->foreign('product_id')->references('product_id')->on('product');
          $table->string('product_snumber');
          $table->integer('customer_name')
          $table->string('order_status');
          $table->timestamps();
          });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
                Schema::dropIfExists('orders');
    }
}

但是我运行 'php artisan migrate' 后,出现以下错误。

[Symfony\Component\Debug\Exception\FatalThrowableError]
解析错误:语法错误,意外的 '$table' (T_VARIABLE)

请帮忙!我正在迁移到 phpmyadmin 数据库。

【问题讨论】:

  • 您是否对迁移进行了交叉检查?那些 unexpected '$table' 可能与缺少 ; 或其他原因有关,只需校对语法..
  • @BagusTesa 是的,我已经交叉检查了我的迁移。显然错误行似乎是'$table->string('order_status');'。知道为什么吗?
  • 对不起,我已经解决了。毕竟它缺少;...
  • 没关系,有时我也错过了一些;
  • 这能回答你的问题吗? PHP parse/syntax errors; and how to solve them

标签: laravel-5.3 database-migration


【解决方案1】:

是的@Bagus Tesa 是对的。 (只是想回答,因为我几乎错过了评论,因为它没有答案) 缺少分号; 可能是问题所在。检查所有修改过的迁移。

【讨论】:

    【解决方案2】:

    检查到另一个迁移中是否有一些字符或丢失了一些东西,就我而言,我忘记了旧迁移中的一个字符:(,删除后对我有用!

    【讨论】:

      【解决方案3】:

      当我将另一个程序 Freemind 1.0.1 中的字段列表剪切并粘贴到 VS Code(1.47.1 之前的那个)时,我发生了错误。一些粘贴的行包括前导空格。 VS Code 不断显示错误,直到所有前导空格都被删除并替换为通常的 Tab 键按下。

      必须开始删除突出显示的错误行上方的前导空格。然后,错误突出显示会逐行跳到代码中,直到消失。

      有时错误从 意外的'$table' 到: 意外''

      由于问题出在前导空格中,因此无法看到,这与缺少分号的解决方案不同。

      【讨论】:

        【解决方案4】:
        $table->integer('customer_name')
        

        缺少分号';'

        同时为了避免在编码时出现这些错误,您应该使用 EA 检查代码插件,通常是气味检查代码和后台检查工具

        【讨论】:

        • 没有必要重复现有的答案——在你回答之前三年多已经给出了确切的提示
        • 我没有意识到
        【解决方案5】:

        此行缺少分号 $table->integer('customer_name') 添加分号 $table->integer('customer_name');

        【讨论】:

        • 没有必要重复现有的答案——在你回答之前三年多已经给出了确切的提示
        • 我还是想回答。如果你觉得它没有用,你可以忽略它。
        猜你喜欢
        • 2019-01-16
        • 2015-05-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多