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]');
$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]>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].
> 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.
>

-- 
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.

Reply via email to