Impossible to generate the table "user" - php

When I install FOSUserBundle (official documentation), I try to generate my table fos_user using this command:
php app/console doctrine:schema:update --force
But console returns the following message
Nothing to update - your database is already in sync with the current entity metadata
I use Symfony 2.1 and the last version to FOSUserBundle.
app/AppKernel.php contains
new FOS\UserBundle\FOSUserBundle(),
app/config/config.yml contains
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Krpano\UserBundle\Entity\User
src/Krpano/UserBundle/Entity/User.php contains
namespace Krpano\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="pouet")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
And when I try to access to my website I have this error:
MappingException: The class 'Krpano\UserBundle\Entity\User' was not found in the chain configured namespaces FOS\UserBundle\Entity, Krpano\ServicesBundle\Entity
Can you help me?

Nothing to update - your database is already in sync with the current entity metadata
Implies that your entity is not registred because of a missing declaration in AppKernel.php.
Doctrine only search on bundle who are active.
After added the line :
new Krpano\UserBundle\KrpanoUserBundle(),
Like that:
public function registerBundles()
{
$bundles = array(
...
new Krpano\UserBundle\KrpanoUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
...
); ...
Try this:
php app/console doctrine:schema:update --force
If Doctrine return:
Database schema updated successfully! "1" queries were executed
Your problem is resolve.
My answer is just a completion to Carlos Granados answer.

Add
new Krpano\UserBundle\KrpanoUserBundle(),
To your app/AppKernel.php file

I had this error and it was caused by having accidentally deleted the #ORM\Entity() line from my entity class. D'oh.

I had the same issue just like you. You missed to create yml for Doctrine Entity. This file is needed for Doctrine to generate shema in your database.
# src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
Acme\UserBundle\Entity\User:
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
Then in console update autoload for composer
composer dump-autoload
Then call Doctrine schema builder
php app/console doctrine:schema:update --force

Using composer.phar dump-autoload --optimize
Also provokes this error, when running:
php app/console cache:clear --env=prod --no-debug
If you run:
./composer.phar update
again it all works again.

Related

Symfony3 error Namespace does not contain any mapped entities

I tried generate getters and setters in Symfony 3.0.1
when i run command
php bin/console doctrine:generate:entities VendorName/MyBundle/EntityName
i have error
Namespace "VendorName\MyBundle\EntityName" does not contain any mapped entities.
where is the mistake?
Edit-1: First generate entity with YAML format
Edit-2: I tried generate getters and setters for vendor bundle
Also i try with command php bin/console doctrine:generate:entities VendorNameMyBundle:EntityName and have another error:
Can't find base path for "VendorName\MyBundle\Entity\EntityName" (path: "/home/site/vendor/vendorname/mybundle/Entity", destination: "/home/site/vendor/vendorname/mybundle/Entity").
As John Pancoast points out in his answer to a different question:
Doctrine does not support PSR-4 when doing anything with code generation. It has to do with how they map class namespaces to filesystem paths and how PSR-4 allows class/namespace paths that don't directly map to the filesystem.
https://github.com/doctrine/DoctrineBundle/issues/282
To clarify what exactly is needed to resolve the error message; You have to edit your bundle's composer.json file, and also change the bundle's folder structure.
in composer.json change psr-4 to psr-0:
"autoload": {
"psr-4": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},
to:
"autoload": {
"psr-0": { "Acme\\Bundle\\AwesomeBundle\\": "" }
},
Change bundle's folder structure from:
vendor
+--acme
+--awesome-bundle
|--Controller
|--Entity
to:
vendor
+--acme
+--awesome-bundle
+--Acme
+--Bundle
+--AwesomeBundle
|--Controller
|--Entity
The following command will no longer throw an exception:
bin/console doctrine:generate:entities AwesomeBundle
You have mistake in command, you trying to generate entities but you provide class name for one entity. Try the following for all entities:
php bin/console doctrine:generate:entities VendorName/MyBundle
or if you want just one entity:
php bin/console doctrine:generate:entity VendorName/MyBundle/EntityName
Symfony 3.22 with src/AppBundle/Entity/User.php
if you add new field using ORM
**/**
* #ORM\Column(name="last_login", type="datetimetz")
*/
private $lastLogin;**
just use
use php bin/console doctrine:generate:entities AppBundle
it will check all your Entities r and update getters and setters
then use
php bin/console doctrine:schema:update to update your database
use
php bin/console doctrine:schema:update --force in PROD enviroment

Symfony cache:clear Semantical Error with #Method Anotation

on my production build when I run:
php app/console cache:clear --env=prod --no-debug
Symofny throws AnnotationExeption
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Cannot import resource "<path>/App/AppBundle/Controller/DefaultController.php" from "<path>/App/AppBundle/Resources/config/routing.yml". ([Semantical Error] The class "Method" is not annotated with #Annotation. Are you sure this class can be used as annotation? If so, then you need to add #Annotation to the _class_ doc comment of "Method". If it is indeed no annotation, then you need to add #IgnoreAnnotation("Method") to the _class_ doc comment of class #Sensio\Bundle\FrameworkExtraBundle\Configuration\Method.)
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The class "Method" is not annotated with #Annotation. Are you sure this class can be used as annotation? If so, then you need to add #Annotation to the _class_ doc comment of "Method". If it is indeed no annotation, then you need to add #IgnoreAnnotation("Method") to the _class_ doc comment of class #Sensio\Bundle\FrameworkExtraBundle\Configuration\Method.
Not sure why, on my localcomputer it's working fine. And other projects using symfony annotations are working fine.
Packages versions: http://pastebin.com/71ZNrwSc
It has been solved with
"sensio/framework-extra-bundle": "dev-master",
Same as this issue
Symfony2 ParamConverter not associated with #Annotation (cache must be cleared after any file change)
Related issue: https://github.com/symfony/symfony/issues/7283

Symfony2 - "Warning: class_parents(): Class Ambience does not exist and could not be loaded in "

I am trying to create an entity using yml and I am getting the following error:
[ErrorException]
Warning: class_parents(): Class Ambience does not exist and could not be loaded in C:\wamp\www\demo\vendor\gedmo-doctrine-extensions\lib\Gedmo\Mapping\ExtensionMetadataFactory.php line 80
I have created a file named Entities.UserTestDelete.dcm.yml in FooBundle/Resources/config/doctrine/metadata/orm
Contents of file:
Entities\UserTestDelete:
type: entity
table: users
id:
id:
type: integer
generator:
strategy: AUTO
fields:
name:
type: string
length: 50
Then I executed the following command:
php app/console doctrine:mapping:import "DemoFooBundle" yml
And then I got the error. Any idea why would that be a problem?
Just had the same problem ... and managed to solve ...
a var_dump($this) on __contruct of the exception class, in my case:
Symfony\Component\Debug\Exception\ContextErrorException
got me the $message->$trace, which led me to:
vendor/sylius/resource-bundle/EventListener/LoadORMMetadataSubscriber.php
calling function "class_parents"
in function "setAssociationMappings"
So quick fix is to simply comment out the subscribed event:
/**
* #return array
*/
public function getSubscribedEvents()
{
// return array(
// 'loadClassMetadata',
// );
}
now when running "app/console doctrine:mapping:import" again ... there won't be anymore errors ...
also if needed, run the mapping:convert and generate:entities command before enabling / uncommenting the subscribed Event again ...
If you are not using Sylius, try var_dump'ing on your exception class ... there's a good chance you too got some Eventlistner interfering with Doctrine's Import command ...
good luck!
Update
Your first mistake is that you created the yml file. As explained in the cookbook, the doctrine:mapping:import command actually generates the file. Ditch yours, run the command, and let doctrine generate the file itself.
What you do afterwards, is generate the actual entity classes:
php app/console doctrine:mapping:convert annotation ./src
php app/console doctrine:generate:entities DemoFooBundle
If the tables themselves don't exist yet, then you can use these last 2 commands to generate the entities, and then run
php app/console doctrine:schema:update --force
To have doctrine create the tables for you.
A quick look in the cookbook tells me that the bundle name should not be quoted, and that you might want to pass the --force flag to the doctrine:mapping:import command.
It's in the reverse-engineering bit
php app/console doctrine:mapping:import --force DemoFooBundle yml
That's the example Symfony2 cookbook gives, only changed to take yml, instead of xml format.
The error message could also be related to the table name:
table: users
Where the entity is called
class Users
{}
possible related question

Symfony2 No Metadata Classes to process

After creating entity with:
php app/console doctrine:generate:entity
and while using:
php app/console doctrine:schema:update --force
I encountered:
No Metadata Classes to process.
Entity
namespace ISLab\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="menu_items")
*/
class MenuItem
{
/**
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(name="parent", type="integer")
*/
private $parent;
// ...
}
I had a similar problem and took me a while until I find out how to clear out the cache. Clearing only doctrine's cache did not work for me. Use the command below to clear the entire environment (production one in this case)
php app/console cache:clear --env=prod
I had the same problem when I generate an Entity through the interactive generator from command line. When I first created I set the Configuration Format to PHP and that didn't work. So I deleted it and tried again but this time I selected format = annotation. Then it worked! Maybe this could solve someone's problem.
So entity manager didn't create metadata for your entity. Here are things I would check first:
Clear your cache
Make sure your AdminBundle is registered in AppKernel.
Make sure that entity manager's automapping is true. Or set it up correctly if you're using custom EM.
A bit offtopic:
I see you're making a menu system and I would strongly suggest you to check out Doctrine Extensions Tree which should allow you to query and edit items much more efficiently than with your structure.
I had the same problem when i update the database.
So i follow this solution and i tried to adapt in my case and it works.
I think that is a problem of automapping indeed also with auto_mapping setted true, symfony wasn't able to find the entities.
I hope that it can help.
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
AppBundle:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/AppBundle/Entity/
prefix: AppBundle\Entity
alias: AppBundle
for anyone on the same thing, these are few steps to go:
1. Clear the cache:
bin/console c:c --env=dev
bin/console c:c --env=prod
If you see any errors meanwhile, try to cover it by inspecting source of problem.
2. Inspect your configuration:
According to this sample directory structure:
Application
|
└- src
|
└- Acme
|
└- Bundle
|
└- BlogBundle
|
└- Model
|
└- Entity
You should have this configuration inside your app/config/config.yml file:
doctrine:
...
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
AcmeBlogBundle:
mapping: true
type: annotation
dir: Model/Entity
alias: Blog
prefix: Acme\Bundle\BlogBundle\Model\Entity
is_bundle: true
3. Update your database schema:
You can now update your database schema without any problems:
bin/console doctrine:schema:update
despite of this being the final step for most cases, you may still use --verbose to find any further possible problems.
bin/console doctrine:schema:update --verbose
Make sure your entities are placed in your bundle's Entity directory. In my case they were in Entities instead.
For me generating all the entities from the cmd did the work.
In my case, i solve the problem creating the Entity folder. For some reason it had been eliminated. I hope that it can help.
I've had the same issue. For me it was that my directory called 'Entity' was not in the 'AppBundle' but in the 'src' directory. Moving the 'Entity' directory into the 'AppBundle' directory fixed the problem for me!

Installing Doctrine extensions in a Symfony 2 project causes Fatal Error

Here is the problem : I don't succeed to install doctrine extensions with symphony 2, especially timestampable. I follow this tutorial
How I proceed :
I add this lines in deps file :
[gedmo-doctrine-extensions]
git=http://github.com/l3pp4rd/DoctrineExtensions.git
[Stof-DoctrineExtensionsBundle]
git=https://github.com/stof/StofDoctrineExtensionsBundle.git
target=/bundles/Stof/DoctrineExtensionsBundle
Then I enter the line
./bin/vendors install --reinstall
All is fine.
Then I activate extensions in concerned files
# config.yml
stof_doctrine_extensions:
default_locale: fr_FR
orm:
default:
timestampable: true
# AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
[...]
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
[...]
);
# autoload.php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Gedmo' => __DIR__.'/../vendor/gedmo-doctrine-extensions/lib',
'Stof' => __DIR__.'/../vendor/bundles',
[...]
));
At last, I add annotate my entity
/**
* #var datetime $updatedAt
*
* #ORM\Column(name="updated_at", type="datetime")
* #Gedmo:Timestampable(on="update")
*/
private $updatedAt;
But I have this error :
Fatal error: Class 'Gedmo\Timestampable\TimestampableListener' not found in /Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 203
What do I do wrong ?
Using #Gedmo\Timestampable(on="update") and putting the right path when registering the namespace seems to solve the problem.
For Symfony 2.0.x and Doctrine 2.1.x. projects you'll need to specify the compatible versions of the extensions in deps, this is what worked for me:
[DoctrineExtensions]
git=https://github.com/l3pp4rd/DoctrineExtensions.git
target=/gedmo-doctrine-extensions
version=origin/doctrine2.1.x
[StofDoctrineExtensionsBundle]
git=https://github.com/stof/StofDoctrineExtensionsBundle.git
target=/bundles/Stof/DoctrineExtensionsBundle
version=1.0.2

Categories