【问题标题】:Laravel 5.4 migrationLaravel 5.4 迁移
【发布时间】:2017-11-06 19:56:51
【问题描述】:

我正在使用 Laravel 5.4 开发学校管理系统。当我迁移数据库表时,我收到此错误消息:

[Symfony\Component\Debug\Exception\FatalThrowableError] 解析错误: 语法错误,意外的 '100' (T_LNUMBER),需要 ',' 或 ')'

请帮帮我,我该如何解决这个错误?

迁移:

public function up() { 
Schema::create('students', function (Blueprint $table) { 
$table->increments('student_id'); $table->string('first_name',50); $table->string('last_name',50); $table->date('dob'); 
$table->string('100')->nullable(); $table->string('status'); 
$table->string('current_address',255)->nullable(); 
$table->foreign('user_id')->references('user_id')->on('users‌​'); 
//$table->timestamps(); 
}); }

【问题讨论】:

  • 我尝试了很多次并检查我的表架构
  • 我的意思是请与我们分享您的一些工作。
  • 是数据库表 public function up() { Schema::create('students', function (Blueprint $table) { $table->increments('student_id'); $table-> string('first_name',50); $table->string('last_name',50); $table->date('dob'); $table->string('100')->nullable(); $ table->string('status'); $table->string('current_address',255)->nullable(); $table->foreign('user_id')->references('user_id')->on( 'users'); //$table->timestamps(); }); }
  • 不要将其添加为评论,编辑您的问题并在此处添加迁移文件。
  • 在括号中命名 $table->string('100')->nullable();示例:string('name',100)

标签: laravel migration


【解决方案1】:

这是不允许的:

$table->string('100')->nullable();

你可能在尝试做这样的事情:

$table->string('somestring', 100)->nullable();

【讨论】:

  • 我更正了这个字段,但它不起作用,,,,,,得到相同的错误信息
  • 您是否在更改后重新运行了迁移?
  • 是的,更改后我会迁移这个数据库
【解决方案2】:

我假设您使用的是 mysql 数据库,在 mysql 数据库中,列名不能是完整的数字字符,除非您将它们放在引号中。参考doc here。 它说,

标识符可以以数字开头,但除非被引用,否则标识符可能不完全由数字组成。

我认为这是您的错字。如果您真的想将您的列命名为 100,请考虑将其重命名为 field100 或类似名称。

【讨论】:

    猜你喜欢
    • 2017-07-14
    • 2017-07-26
    • 2017-08-29
    • 2018-12-06
    • 2017-06-23
    • 2017-10-05
    • 2018-06-20
    • 2019-12-27
    • 2018-04-18
    相关资源
    最近更新 更多