-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
automatically update and create date and time based fields (not a bug) #131
Comments
You could set a default on the column in your schema. And if you don't want
that in general, you could set it at the beginning of the migration and
alter the table later.
…On Thu, Sep 12, 2019, 12:16 zsan ***@***.***> wrote:
Hi,
I am starting to use DBIx::Class::Migration, i have followed the
tutorials and i have question.
So i have this migration script
use strict;
use warnings;
use DBIx::Class::Migration::RunScript;
migrate {
my $user_rs = shift->schema->resultset('User');
$user_rs->create({
name => 'foo',
email => ***@***.***',
# created_at => DateTime->now,
# updated_at => DateTime->now,
});
};
And that will fail with message
DBI Exception: DBD::Pg::st execute failed: ERROR: null value in column "created_at" violates not-null constraint
DETAIL: Failing row contains (1, ***@***.***, foo, null, null). [for Statement "INSERT INTO users ( email, name) VALUES ( ?, ? ) RETURNING id" with ParamValues: ***@***.***', 2='foo'] at /Users/zak/Projects/mojolicious/tutorials/minipost/share/migrations/_common/deploy/1/002-demo.pl line 8
and my user's schema
use utf8;
package Minipost::Schema::Result::User;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->load_components("TimeStamp");
__PACKAGE__->table("users");
__PACKAGE__->add_columns(
"id",
{
data_type => "bigint",
is_auto_increment => 1,
is_nullable => 0,
sequence => "users_id_seq",
},
"email",
{
data_type => "text",
is_nullable => 1,
original => { data_type => "varchar" },
},
"name",
{
data_type => "text",
is_nullable => 1,
original => { data_type => "varchar" },
},
"created_at",
{
data_type => "timestamp",
is_nullable => 0,
set_on_create => 1
},
"updated_at",
{
data_type => "timestamp",
is_nullable => 0,
set_on_create => 1,
set_on_update => 1,
},
);
__PACKAGE__->set_primary_key("id");
1;
Is there a way to install the migration without having to type the value
of created_at and updated_at ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#131?email_source=notifications&email_token=AFURPKTMVNYQOVCNSNT7SBLQJICH7A5CNFSM4IWBJVSKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HK5YRYQ>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFURPKSOH2VILEONT74YPE3QJICH7ANCNFSM4IWBJVSA>
.
|
So actually i have set it on my schema via |
Does it set the default on the database side? Could you link to a full (non)working example? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am starting to use
DBIx::Class::Migration
, i have followed the tutorials and i have question.So i have this migration script
And that will fail with message
and my user's schema
Is there a way to install the migration without having to type the value of
created_at
andupdated_at
?The text was updated successfully, but these errors were encountered: