php - How to create database table from entity in symfony 2.6 -
what i've done far -> have created bundle , entity class in , created database table named "news" entity class using following command
php app/console doctrine:schema:update --force
everything went well.
now created new bundle , other entity class in want create other table in database named "user" gives error "the table name 'symfony.news' exists' ".
class user { private $id; private $useremail; public function getid() { return $this->id; } public function setuseremail($useremail) { $this->useremail = $useremail; return $this; } }
your entity doesn't contain annotations, , doctrine have no idea entity. if add entity like:
<?php namespace appbundle\entity; use doctrine\orm\mapping 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 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 resources/config/doctrine/
directory, you'll able run command:
php app/console doctrine:schema:update --force
and result you'll receive:
updating database schema... database schema updated successfully! "1" queries executed
truly believe solve problem...
Comments
Post a Comment