2

I'm having a similar problem that is explained in this post but the offered solution does not work in my case. Here's the issue...

I am using Symfony2, which uses Doctrine2 for the ORM, to insert new users into the database. When I use the object method to insert the user, a null value is inserted into fields that I don't want to insert anything into (so the default value will be inserted).

This is how I want the generated INSERT statement to look:

INSERT into mytable (name) VALUES (?)
array(1) {
  [1]=>
  string(6) "myName"
}

And this is how Doctrine creates the INSERT statement

INSERT into mytable (name, token, creationDate) VALUES (?,?,?)
array(3) {
  [1]=>
  string(6) "myName"
  [2]=>
  NULL
  [3]=>
  NULL
}

The token should have a default value that is defined using postgresql's uuid_generate_v5 method. The creationDate should have a default of now(). The NULL values that doctrine is inserting override these default values.

Is there any way to get doctrine to ignore certain fields on insert?

4

1 回答 1

1

尝试在列注释中显式使用 nullable=false 属性。

于 2013-09-25T20:56:52.610 回答