Laravel迁移给表添加字段,但是Laravel添加了双引号

标签 laravel postgresql

我已添加此迁移以将字段添加到我的 admission 表中。 问题是它在 postgres 中用双引号创建了一些字段。
下面是来自同一迁移的两个字段。一个是用引号创建的,另一个没有。

为什么会这样?我认为这可能与数据类型有关,但我还有其他用引号创建的整数字段。

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class addReferralFields extends Migration
{
    public function up()
    {
        Schema::table('admission', function (Blueprint $table) {
            if (!Schema::hasColumn('admission', 'appointmentDate')) $table->timestampTz('appointmentDate')->nullable();
            if (!Schema::hasColumn('admission', 'appointment_pre_employment_status')) $table->integer('appointment_pre_employment_status')->nullable();



        });
    }
}

入场表

  "apointmentDate" timestamp(0) with time zone,
  appointment_pre_employment_status integer,

最佳答案

我所做的只是运行另一个迁移以将所有字段名称设置为小写。

public function up()
{
    Schema::table('admission', function(Blueprint $table) {

        $table->renameColumn('"apointmentDate"', 'apointmentdate');

    });
}

关于Laravel迁移给表添加字段,但是Laravel添加了双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58299579/

相关文章:

python - 有什么方法可以处理 DB uri 中的断开连接吗?

postgresql - postgres 将数据库复制到另一台服务器可减少数据库大小

asp.net - 数据库连接 ASP.NET - PostgreSQL

php - 为什么在 Laravel 中自定义用户提供程序身份验证后我会收到此 "These credentials do not match our records"消息?

sql - Hibernate 空字符串用于 PostgreSQL 8.3 和 Oracle 11g 的相等限制

json - Laravel:更新嵌套的 json 对象

php - Laravel 单元测试,如何软删除 "seeInDatabase"行?

java - 触发器生成的自动刷新字段

php - 拉维尔 4 : Where Not Exists

php - Laravel Eloquent 更新 tinyint (boolean)