I have problem with deploying of symfony2 app. I get the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table '14271425_sjokh.Books' doesn't exist
I have found out that this error is connected with case issue.
The given table exists on server but is called books not Books.
I have tried to solved this by modyfing config.yml, adding to it naming_strategy: doctrine.orm.naming_strategy.underscore (as proposed here: Symfony2: Base table or view not found: 1146) but it did not helped.
doctrine:
orm:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
Doctrine underscore naming strategy doesn't pluralize entity names, like it's case in RoR for example.
So, for Book entity, underscore strategy expects table named book. For SomeCamelcase entity, it expects some_camelcase table.
You should either rename your table or tell doctrine what table name is through config. If using annotations for example, it will be:
/**
* #ORM\Table(name="books")
*/
class Book
{
// ....
}
It seems that my problem was connected with wrong cases in doctrine annotations.
I have deleted the following code:
* #ORM\Table(name="Books")
and this together with edit of config file adding:
doctrine:
orm:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
made the script working.
Related
Today i tried to copy/past an entity from a project to an other.
First i tried to create the entity with
php bin/console make:entity
And to copy/past the entity class into the file just created.
Didn't work and got this error message i can't figure out.
My configuration is a new symfony 5.4 project. And symfony 5.4 for the other project.
The only things that change is that in the first projet i used annotation system (#ORM\Table...) and the new one is attributes by default (#[ORM\...). But i used to use both on other projects and worked well.
I tried to change annotation to attribute and it works. But i would like to know how can i use both annotations and attributes on the project, it used to be the default value ?
My doctrine.yaml :
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '14'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
What i tried :
cache clear
remove/create entity
check on internet for some solutions
check if use Doctrine\ORM\Mapping as ORM; was in my file
What i tried :
cache clear
remove/create entity
check on internet for some solutions
check if use Doctrine\ORM\Mapping as ORM; was in my file
Symfony does not support both, you have to choose between of 2, so if you don't have any php version problem, both should fit
I would like to use bootstrap 4 CoreUi template in my symfony project.
I added it to my project with
composer require coreui/coreui
Now coreui is in my vendor directory, I would like to add a path in twig.yaml to simplify its access, according to the doc I modified my twig.yaml file like this :
twig:
# paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
paths:
- '%kernel.project_dir%/templates'
- '%kernel.project_dir%/vendor/coreui': coreui
I get an ErrorException :
Notice: Undefined index: value
The doc doesn't say much... so I don't know what to do at this point.
Apologies for posting the wrong link in my comments. The error you are getting is a twig "feature". Basicially just need to supply a value for the blank namespace.
twig:
#paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
paths:
#'%kernel.project_dir%/templates': '' # add : ''
'%kernel.project_dir%/vendor/coreui': coreui
Run bin/console debug:twig and all should be well.
Update: Based on the discussion below with #yceruto as well as this github issue, I changed the answer to simply comment out the default templates line. Turns out it is not needed and there is a pull request to remove it. Always wondered why it was there in the first place.
paths: is getting two parameters as array, here
%kernel.project_dir%/templates and %kernel.project_dir%/vendor/coreui are directories must be exists, if not exists you need to create or just remove if don't need one of.
Mine is like that:
twig:
paths: ['%kernel.project_dir%/templates']
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
I have a question regarding YAML configuration of Doctrine in Symfony2.
I have created an entity via "doctrine:generate:entity", and chose YAML as the mapping format.
This didn't add any metadata on ../Entity/"MyEntity".php, which would allow me to update or create my schema.
As an example, if I run
./app/console doctrine:schema:create
it fails, saying:
[RuntimeException]
Bundle "MySuperBundle" does not contain any mapped entities.
My automapping is already set to "true".
If I choose to use annotation config this would not be a problem.
Did I miss something? Are there any extra steps that I should take?
Thank you in advance, regards,
Ivan
I just had a fun time looking at the Doctrine config initialisation code. What I found was:
Using auto_mapping results in various defaults being set for the single default entity manager; it leaves the type value as false
If type is false the config code looks into the default directory for likely config files, and as soon as it finds a file of a valid extension it decides that that's the way config is being done, in the order xml, yml, php
If it doesn't find any of those it assumes annotation
Do you have anything else at all in the Bundle/Resources/config/doctrine folder? If so, it might be throwing off the auto-detection.
That aside, basically if you've used defaults, and have some entity classes and valid config, what you're doing should be working without any additional config. You've said "auto_mapping" is true, but have you changed any other bit of Doctrine config?
It might be an idea to try configuring stuff explicitly, e.g. as described in the Symfony Doctrine docs, go from default config
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
to explicit
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MySuperBundleName:
type: yml
dir: Resources/config/doctrine
I'm using DoctrineMongoDBBundle, normally i put the documents into the MyBundle/Document directory and works fine but i want change to MyBundle/Model
after move my documents to new namespace i get a error message
[Exception]
You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles...
currently i'm using annotations for set the configuration, i dont want use xml or yml. this is the current config, how i can achieve this?
# app/config/config.yml
doctrine_mongodb:
connections:
default:
server: mongodb://localhost:27017
options: {}
default_database: "%database_name%"
document_managers:
default:
auto_mapping: true
Assuming your document is Acme/Model/Invoice.
You can adjust the mapping like this:
doctrine:
odm:
# ...
mappings:
Acme:
type: annotation
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: MyDocuments
Now use the the mapping like this:
$documentManager->getRepository('MyDocuments:Invoice');
If you want to keep the document inside a bundle ...
... just use the bundle's name i.e. AcmeDemoBundle instead of Acme as the mapping-name, set is_bundle to true and the dir option will be seen as relative to the bundle's root directory.
More information on the mapping options can be found in the documentation chapter DoctrineBundle Configuration#Mapping Information.
More information on how to store documents out of bundles can be found in this blog post.
The procedure is the same for Doctrine ORM btw.
I am trying to store entities in MyBundle/OtherNamespacePart/Entity directory.
If I run doctrine:schema:create, i get this error message:
Class MyBundle/Entity/MyEntity does not exist and could not be loaded.
I don't get, why is "OtherNamespacePart" ignored (should be MyBundle/OtherNamespacePart/Entity/MyEntity). I checked whole project if there is everything namespaced and named correctly and it seems to me ok. If i store entities directly in entity directory, it works (just need to remove all "OtherNamespacePart").
Isn't problem in console command tool, that expects entities in entity directory? Is there any workaround or configuration option?
You can do this by providing custom mappings in your config.yml
e.g.:
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: false
mappings:
name:
type: xml
dir: %kernel.root_dir%/../src/Your/Bundle/Resources/config/doctrine
alias: MyModels
prefix: MyBundle\OtherNamespacePart\Entity
is_bundle: false