1

Working with Laravel 5.5 Migrations with Postgres :

1) Defining field as :

$table->enum('is_applied', ['Y', 'N']) ->comment('Y => is_applied, N=> Is not applied');

I see in generated table next:

is_applied varchar(255) NOT NULL,
    CONSTRAINT cs_tmp_csvps_is_applied_check CHECK (((is_applied)::text = ANY ((ARRAY['Y'::character varying, 'N'::character varying])::text[]))),

actually I would like to get sql I used in Postgres with type:

CREATE TYPE type_cms_item_content_type AS ENUM (
    'P',
    'M',
    'H'
);

    content_type type_cms_item_content_type NOT NULL DEFAULT 'P'::type_cms_item_content_type,

Is it possible?

2) Defining field as :

$table->timestamps();

I have 2 fields created created_at and updated_at . As I need to create only created_at I could write :



$table->dateTime('created_at');

But is there is a way to set default time on server, like :

created_at timestamp NOT NULL DEFAULT now(),

?

Thanks!

2 Answers 2

1

You can do:

$table->timestamp('created_at')->useCurrent();

for the timestamps issue. If you really want exact sql changes you can always do a raw sql statement in a migration:

Schema::table('content_type', function(Blueprint $table){
    $sql = 'CREATE TYPE type_cms_item_content_type AS ENUM (
    `P`,
    `M`,
    `H`
);

    content_type type_cms_item_content_type NOT NULL DEFAULT `P`::type_cms_item_content_type';
    DB::connection()->getPdo()->exec($sql);
});
Sign up to request clarification or add additional context in comments.

Comments

1

1) Defining field as:

$table->enum('is_applied', ['Y', 'N']) ->comment('Y => is_applied, N=> Is not applied');

The method comment() it's only for MySQL, in the Migrations on Laravel.

See for more details: https://laravel.com/docs/5.5/migrations#creating-columns

2) Defining field as:

The Answer of @alex-harris is a gob option

$table->timestamp('created_at')->useCurrent();

See: https://laravel.com/docs/5.5/migrations#column-modifiers for more details

2 Comments

Thanks! I did not find if there is some option for updated_at, like useCurrent but updating?
@user2339232 see the issue in GitHub github.com/laravel/framework/issues/10005 You can modifie your Model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.