'How to create database table from entity in symfony 2.6

what i've done so far is -> i have created a bundle and entity class in it and created a database table named "news" from that entity class using following command

php app/console doctrine:schema:update --force

everything went well.

now i created a new bundle and an other entity class in it from which i want to create an other table in database named "user" but gives an error that "The table with name 'symfony.news' already exists' ".

class user { 
   private $id; 
   private $userEmail; 

   public function getId() { 
       return $this->id; 
   } 

   public function setUserEmail($userEmail) { 
       $this->userEmail = $userEmail; 
       return $this; 
   } 
}


Solution 1:[1]

Your entity doesn't contain annotations, and doctrine have no idea what to do with this entity. But if you add to you entity something like:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=60, unique=true)
     */
    private $email;

    public function getId()
    { 
        return $this->id; 
    } 

    public function setUserEmail($userEmail)
    { 
        $this->userEmail = $userEmail; 
        return $this; 
    }
}

OR

if you add file: User.orm.xml like:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="AppBundle\Entity\User" table="user">
    <unique-constraints>
      <unique-constraint name="UNIQ_797E6294E7927C74" columns="email"/>
    </unique-constraints>
    <id name="id" type="integer" column="id">
      <generator strategy="IDENTITY"/>
    </id>
    <field name="email" type="string" column="email" length="60" nullable="false"/>
  </entity>
</doctrine-mapping>

to your Resources/config/doctrine/ directory, you'll be able to run command:

php app/console doctrine:schema:update --force

and as result you'll receive:

Updating database schema...
Database schema updated successfully! "1" queries were executed

Truly believe that it will solve your problem...

Solution 2:[2]

For symfony 4 and 4++:

php bin/console doctrine:schema:update --force

For symfony 3:

php app/console doctrine:schema:update --force

Solution 3:[3]

If neither "php app/console doctrine:schema:update --force" nor "php bin/console doctrine:schema:update --force" (you probably work on windows..) is working out, you may try:

"php artisan doctrine:schema:update --force".

Only thing worked out for me.

Solution 4:[4]

Why don't you use doctrine command?

php app/console doctrine:generate:entity 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Cristik
Solution 4 Stev