Some diverse thoughts of directions to explore:
1. Maybe you already have bannedEmail entities in the database before
executing this code? That could interfere with this. Try testing with an
empty table as a start.
2. The error is from PDO, not from the ORM. There probably is a
constraint in the database about a rule-field that is not null. Maybe you
can delete such an extra constraint. Maybe you should define a fresh new
table and test with that.
3. What is the SQL that is generated and what do you get if you play
with that table directly in PhpMyAdmin?
4. Look on internet for everything written about "Integrity constraint
violation: 1048 Column cannot be null". Maybe you'll find a hint on
something that can lead to understanding what went wrong.
5. Trace back every step in the underlying code and look what queries
are generated etc. to find the exact place where things go wrong.
After it works I would look at your model and reconsider if entities with
nothing more than their ID is the best way to model what you want. Maybe
you can find some alternatives.
On Friday, 18 April 2014 21:35:57 UTC+2, Parsifal wrote:
>
>
> I remove uniqueConstraints and changed it to:
> $metadata->setPrimaryTable(array(
> 'name' => 'banned_emails',
> ));
> $metadata->mapField(array(
> 'fieldName' => 'rule',
> 'columnName' => 'rule',
> 'type' => 'string',
> 'nullable' => false,
> 'unsigned' => false,
> 'comment' => '',
> 'id' => true,
> ));
>
> And I am still getting this:
>
> "START TRANSACTION" INSERT INTO banned_emails (rule) VALUES (null)
> "ROLLBACK"
> Fatal error: Uncaught exception 'PDOException' with message
> 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'rule' cannot
> be null' in /vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php:165 Stack
> trace: #0 /vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php(165):
> PDOStatement->execute(NULL) #1
> /vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php(279):
>
> Doctrine\DBAL\Statement->execute() #2
> /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(952):
> Doctrine\ORM\Persisters\BasicEntityPersister->executeInserts() #3
> /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php(335):
> Doctrine\ORM\UnitOfWork->executeInserts(Object(Doctrine\ORM\Mapping\ClassMetadata))
>
> #4 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(389):
> Doctrine\ORM\UnitOfWork->co in
> /vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php on line 91
>
> The code I am using is:
> $banned = new Entities\BannedEmail;
> $banned->setRule('[email protected] <javascript:>');
> $em->persist($banned);
> $em->flush();
>
> and the method within class is:
> public function setRule($email)
> {
> $this->rule = $email;
> }
>
> any idea?
>
>
>
>
>
> On Fri, Apr 18, 2014 at 11:38 PM, Herman Peeren
> <[email protected]<javascript:>
> > wrote:
>
>> On Friday, 18 April 2014 18:09:11 UTC+2, Parsifal wrote:
>>>
>>> I guess doctrine actually requires an integer primary key?
>>>
>>
>> No, that is certainly not the case, fortunately.
>>
>> On Friday, 18 April 2014 18:09:11 UTC+2, Parsifal wrote:
>>
>>> or there should be some mistakes in $metadata->mapField?
>>> Anyway, I did not write it myself it was generated by convert-mapping, I
>>> just created a table with rule as primary key and generated
>>> convert-mapping. what is wrong there? should I change something in
>>> $metadata->mapField or in db?
>>>
>>
>> Yes, but I don't know exactly what happens. A wild guess: making the
>> rule-field the id in the mapField() makes that column already needing
>> unique values. So there is no need for that uniqueConstraints-attribute in
>> the Table-setting. Maybe by also defining that it wants to generate a
>> rule-column besides the primary key. It's just a bit vague idea. I would
>> first try to leave that uniqueConstraints-part out. Do you then still get
>> the same error-message?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.