Small error but I don't see where - Symfony Foreign keys

A beginner

Hey guys i have an error (i think that i do a really idiot error but i don't see were) trying to waste time i ask you the question. The error is that my foreign keys is incorrectly formed. Cannot be more precise ... Thx to all people who will try to answer or search :p

My UserInterestEntity :

/**
* UserInterest
*
* @ORM\Table(name="user_interest", indexes {@ORM\Index(name="userInterest_category_id_fk", columns={"category_id"})})
* @ORM\Entity
*/
class UserInterest
{

/**
 * @var \AppBundle\Entity\Category
 *
 * @ORM\Id
 * @ORM\ManyToOne(targetEntity="Category")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="category_id", referencedColumnName="id")
 * })
 */
 private $category;
 }

My Category Entity :

/**
* UserInterest
*
* @ORM\Table(name="Category", uniqueConstraints {@ORM\UniqueConstraint(name="category_id_uindex", columns={"id"})})
* @ORM\Entity
*/
class Category
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 * @ORM\OneToOne(targetEntity="UserInterest", inversedBy="Category")
 */
protected $id;

The error is that when i do : php bin/console doctrine:schema:update --force tat tells me : Foreign key constraint is incorrectly formed

nusje2000

The relation must not be mapped on the ID but on a separate property. On the category class you can create an userIntrests property defining the userIntrests that have this category. In example:

class Category
{
    /**
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\OneToMany(targetEntity="UserInterest", mappedBy="category")
     */
    protected $intrests;
}

class UserIntrest
{
   /**
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id()
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id

    /**

     * @ORM\ManyToOne(targetEntity="Category", inversedBy="intrests")
     */
    protected $category;
}

Use this for reference https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/association-mapping.html#one-to-many-bidirectional

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Stored procedure throwing error on execution, I don't see the incorrect syntax where the error says

Typescript error TS1005: ';' expected but I don't see where I'm missing a semicolon

"let is unfinished. expect an expression" error. I don't see where though

'address already in use', but I don't see where

query error, but I don't know where is it

i am trying to create foreign keys but i got error 1822 .. please see my code below

SQL giving a syntax error, yet I don't see one

Why can't I see the keys of an Error object?

I am learning opencv-python image processing so I wrote this small code but I am getting an error I don't know where I am wrong

A loop that I don't see

Why i don't see response when I type in browser IP and port where nodejs is listening?

There's an error in my syntax, I don't know where

How do I see all foreign keys to a table or column?

Foreign Key (don't want to edit it) error

I don't see where a method is executed Aeron low latency library

Where to start de-verb from ? I don't see any shortcut

foreign ssh login I don't recognize

Syntax Error in SQL in Table Creation Code (i don't see an error...)

Why don't CMS databases use Foreign Keys?

Why I don't see the second plot?

Shutter is running, but I don't see it

I don't see the point of Gradle / Maven

scp : "unexpected filename: . ", but I don't see a "."

How can I model a Struct from JSON where some high level properties don't have keys

Symfony foreign keys (How can i edit them ?)

Why if static method don't involve in polymorphism(late binding) I see error that static method cannot be overridden

Don't see why I'm getting 'numpy.ndarray object not callable' error?

GitHub keeps throwing "Could not commit submodules" error, and I don't see why that is. Any ideas?

Fatal error but i don't see any broken syntax or errors with my funciton