I'm currently trying to get a Symfony project up and running. The problem is when I try to setup the database I keep getting
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Invalid env(resolve:DATABASE_URL) name: only "word" characters are allowed.
I edited the .env file to have my local database credentials. The DATABASE_URL variable looks like the following:
DATABASE_URL="mysql://user:pass#192.168.10.10:3306/db_name?charset=utf8mb4&serverVersion=5.7"
Where of course, user, pass and db_name are the credentials.
Any idea on how to solve this problem?
I found something in doctrine recipe. It's likely because you are using symfony 3.3 with symfony/flex so you would need to remove the resolve keyword, ie. in your config/packages/doctrine.yaml :
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
See this news for more information
I'm trying to reverse engineer a database with Propel 2. But every time i try to run the model:build command i get the following error:
[Propel\Generator\Exception\InvalidArgumentException]
Invalid database name: no configured connection named 'default'
It says "no configured connection"?? but is was able to generate a schema.xml from the database with the "reverse" command?
Thanks in advance.
I found that I am having similar situation.
<database name="somename" ...>
Change the name attribute in <database> in the generated schema.xml to match the connection name in your propel.yaml may solve the problem.
database:
connections:
somename:
adapter: mysql
After finally(!) adding SonataPageBundle to an existing app I get when going to the dev environment
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'volunteer.page__site' doesn't exist
on running php app/console sonata:page:create-site. Nowhere in the documentation for the PageBundle is there any mention of how to create the schema.
If I do doctrine:schema:create --dump-sql to see what's what I get
[Doctrine\DBAL\DBALException]
Unknown column type "json" requested...
A search in the installed PageBundle directory (i.e., not at the Sonata-Project website) revealed the instruction to modify app/config/config.yml with
doctrine:
dbal:
...
types:
json: Sonata\Doctrine\Types\JsonType
With this addition the schema could then be updated and a site created.
If my sanity holds I'll fork the documentation to have it match a known good procedure.
I had an entity class in Aib\PlatformBundle\Entity\User.php
I had no problems trying to create its form class through
php app/ console doctrine:generate:form AibPlatformBundle:User
Now I have change the namespace to Aib\PlatformBundle\Entity\Identity\User, but when I try to generate the form with the task I said before
it says:
"Class Aib\PlatformBundle\Entity\User is not a valid entity or mapped
super class."
This is the file content:
<?php
namespace Aib\PlatformBundle\Entity\Identity;
use Doctrine\ORM\Mapping as ORM;
/**
* Aib\PlatformBundle\Entity\Identity\User
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="Aib\PlatformBundle\Entity\Identity
\UserRepository")
*/
class User
{
...
Any idea?
symfony2.0.4
Had this problem - don't forget the annotation * #ORM\Entity like below:
/**
* Powma\ServiceBundle\Entity\User
*
* #ORM\Entity
* #ORM\Table(name="users")
*/
Had this problem yesterday and found this thread. I created the entity with the mapping in a new bundle (e.g. MyFooBundle/Entity/User.php), did all the configuration according to the docs but got the same error from above when trying to load the app.
In the end I realized that I wasn't loading MyFooBundle in AppKernel:
new My\FooBundle\MyFooBundle()
A great way to debug this is to run this command:
app/console doctrine:mapping:info
Do check your config.yml file, should be containing something like this:
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
types:
json: Sonata\Doctrine\Types\JsonType
orm:
auto_generate_proxy_classes: %kernel.debug%
# auto_mapping: true
entity_managers:
default:
mappings:
FOSUserBundle: ~
# ApplicationSonataUserBundle: ~
YourUserBundle: ~
SonataUserBundle: ~
Add your own bundle to the mappings list.
I resolved this issue by setting $useSimpleAnnotationReader=false when creating the MetaDataConfiguration.
I solved this by passing false as the second parameter to Doctrine\ORM\Configuration::newDefaultAnnotationDriver.
It took me a while of digging through Google and source code.
My case was sort of special since I was using a mapping pointing to another directory unrelated to the Symfony installation as I also had to use legacy code.
I had refactored legacy entities and they stopped working. They used to use #Annotation instead of #ORM\Annotation, so after refactoring it simply failed to read the metadata. By not using a simple annotation reader, everything seems to be okayish.
In my case the problem was solved by changing my servers cache from eAccelerator to APC.
Apparently eAccelerator strips all the comments from files which breaks your annotations.
big thx to Mark Fu and mogoman
I knew it had to be somewhere in the config.yml... and being able to test it against the
app/console doctrine:mapping:info
really helped!
In fact, this command just simply stops at an error... no feedback, but when everything is fine you should be able to see all your entities listed.
I resolved the same exception by deleting a conflicting autogenerated orm.php file in the bundle's Resources/config/doctrine folder; according to the documentation: "A bundle can accept only one metadata definition format. For example, it's not possible to mix YAML metadata definitions with annotated PHP entity class definitions."
Very high possibility that you have PHP 5.3.16 (Symfony 2.x will not work with it). Anyway you should load check page on http://you.site.name/config.php
If you had project not worked on hosting server, next lines must be removed in "config.php":
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
Goodluck!
Entity must have proper Entity and Table annotations (order may matter so try both)
If there is custom repository it MUST be accessed via Entity class itself ($entityManager->getRepository('your ENTITY class name')), as calling it via Repository class name will trick Doctrine into thinking Repo class must be an entity itself. Silly, but Doctrine does not make hard distinction.
My mistake was I was doing
$em->getRepository(EntityRepository::class)
instead of
$em->getRepository(Entity::class)
In my case, I was too zealous during a refactor and had deleted a doctrine yml file!
In my case on my mac I was using src/MainBundle/Resource/Config/Doctrine, of course it worked on Mac but it didn't work on production Ubuntu server. Once renamed Config to config and Doctrine to doctrine, the mapping files were found and it started working.
In my case after making make:entity i tried the following command
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
which generates the entity from the database
However, this Command don t provide the getters and setters that will cause you unknown method error (getId for example) if you are using it inside a controller or you ll use it later So i decided to go back to the generated entity from the
php bin/console make:entity
so i can bring back the missing methods but unfortunately this caused me the error class is not a valid entity or mapped superclass.
next to prevent this error i haven 't patience to read this documentation
[1]: https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/tutorials/override-field-association-mappings-in-subclasses.html#override-field-association-mappings-in-subclasses especially i m using attributes in the place of annotation,
therefore i brought back the generated entity and just adding the following command which generates getters and setters $ php bin/console make:entity --regenerate App
saved my life ,though this solved my problem but i didn t figure out why in the first case it caused me the error of this topic
I got rid of the same error message as in your case by using app/console_dev instead of just app/console
I'm new to Symfony and I'm going through the Jobeet tutorial v1.4 for
Doctrine. I am currently stuck on Day 3. I've followed all the
instructions on configuring the database and building models and
modules; however, when I try to access
"http://localhost:8080/frontend_dev.php" I receive the following
error:
'Configuration "config/databases.yml" does not exist or is unreadable.'
My config/databases.yml file looks like this:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=jobeet'
username: root
password: mysecret
Creating the tables and loading the fixtures seem to work fine after checking the database with phpmyadmin. Any help would be appreciated.
Thank you!
I tried what's in the Jobeet from Day 1 to 3 and it works on my local machine, maybe what you have there is some file permission issue that is preventing your symfony to load the config/databases.yml so please change permissions as needed (chmod in linux).
Not sure if this will solve the problem but I think this is worth to try, execute php symfony cc or simply clear the cache folder and load up again your app in the browser, since the config/databases.yml is to be cached as config_databases.yml.php (you can take a look on /cache/frontend/dev/config/)
phpmyadmin? arrggggghhhhhhh =P
Anyway, your identation is wrong.
It should be like this:
all:
doctrine:
class: sfDoctrineDatabase
param:
dsn: "mysql:host=localhost;dbname=jobeet"
username: root
password: mysecret
As for the error, if you're on a mac, change the permissions using chmod. :-)
If you're stuck on a problem with databases.yml, this symfony databases.yml configuration reference could be useful: www.symfonyreference.com/databases-yml