database error on schema validate with Doctrine - symfony

I'm attempting to create a database using the doctrine orm with an application built by someone else. I'm getting Database errors, and I'm unsure if I'm unclear on the concept, or if I need to adjust the Annotations.
Command and output:
php bin/console doctrine:schema:validate
Mapping
-------
[OK] The mapping files are correct.
Database
--------
15:06:28 ERROR [console] Error thrown while running command "doctrine:schema:validate". Message: "Invalid index-name unique_organization_id_application_id given, has to be [a-zA-Z0-9_]" ["error" => Doctrine\DBAL\Schema\SchemaException { …},"command" => "doctrine:schema:validate","message" => "Invalid index-name unique_organization_id_application_id given, has to be [a-zA-Z0-9_]"] []
[Doctrine\DBAL\Schema\SchemaException]
Invalid index-name unique_organization_id_application_id given, has to be [a-zA-Z0-9_]
It almost sounds like the database isn't set up properly(though I thought this was the first step before setting up the database schema)
The annotation:
#ORM\Table(name="applications", uniqueConstraints={#UniqueConstraint(name="unique_organization_id_application_id", columns={"organization_id", "application_id"})})
And this is where I'm out of my depth. organizationId and applicationId are both private members(?) of the class, with getters and setters. unique_organization_id_application_id isn't found anywhere in the class.

Invalid index-name unique_organization_id_application_id given, has to be [a-zA-Z0-9_]
The error says that you inserted some non-english letters in the index name. Try to completly remove the name.

Related

Entities aren’t updated after changes

I'm new to using Symfony, and today I encountered a problem, I can not change the properties of my entities : Doctrine doesn't want to insert the changes into my database...
I look for answers like for example here, but I did not find the solution.
As I am new, I tried again from a blank project:
I create a new entity:
luc#Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. TinyChef):
> Product
created: src/Entity/Product.php
created: src/Repository/ProductRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
> name
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
Then I make the migration:
luc#Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
Success!
Next: Review the new migration "src/Migrations/Version20191122111110.php"
Then: Run the migration with php bin/console doctrine:migrations:migrate
See https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
I run it:
luc#Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console doctrine:migration:migrate
Application Migrations
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)y
Migrating up to 20191122111110 from 0
++ migrating 20191122111110
-> CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
++ migrated (took 36.5ms, used 16M memory)
------------------------
++ finished in 39ms
++ used 16M memory
++ 1 migrations executed
++ 1 sql queries
And I added a new property to my entity:
luc#Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:entity
Class name of the entity to create or update (e.g. FierceGnome):
> Product
Your entity already exists! So let's add some new fields!
New property name (press <return> to stop adding fields):
> description
Field type (enter ? to see all types) [string]:
>
Field length [255]:
>
Can this field be null in the database (nullable) (yes/no) [no]:
>
updated: src/Entity/Product.php
Add another property? Enter the property name (or press <return> to stop adding fields):
>
Success!
Next: When you're ready, create a migration with make:migration
When I try to create my migration it doesn't work:
luc#Lucs-MacBook-Pro:~/SymfonyTest|master⚡
⇒ symfony console make:migration
[WARNING] No database changes were detected.
The database schema and the application mapping information are already in sync.
Can someone help me? If I didn't understand how it works or something else...
Thank!
I had the same issue. Clearing the cache worked for me.
symfony console cache:clear

Generate admin Sonata with command line in Symfony 4

I'm starting to use Sonata with Symfony 4.
I try to generate an admin with the command line "make:sonata:admin" and i've an error at the end of the process like this:
2018-10-11T15:55:23+00:00 [error] Error thrown while running command "make:sonata:admin". Message: "There are no model managers registered."
In AdminMaker.php line 286:
There are no model managers registered.
So I try wit hthe other command line "sonata:admin:generate" and I have an other error like this :
Welcome to the AdminBundle object ACL generator
This command helps you to generate ACL entities for the objects handled by the AdminBundle.
If the step option is used, you will be asked if you want to generate the object ACL entities for each Admin.
You must use the shortcut notation like AcmeDemoBundle:User if you want to set an object owner.
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
Admin class is using a manager type that has no manipulator implemented : ignoring
My implementation code is like this :
src
Entity
Clients
Vehicules
Can you help me please ?
Thanks a lot for your answer
Try to config the service, so you can give the model manager that you use.
services:
sonata.admin.maker:
class: Sonata\AdminBundle\Maker\AdminMaker
arguments: ['%kernel.project_dir%', ['#sonata.admin.manager.orm']]
tags:
- { name: maker.command }
You need to install Doctrine ORM Admin Bundle first
composer require sonata-project/doctrine-orm-admin-bundle

Symfony2 doctrine:generate:entity and Fatal Parse Error

I'm getting started with Symfony2 and reading the book I got ot the doctrine entity generator code. Used the example in the book:
php app/console doctrine:generate:entity --no-interaction --entity="AppBundle:Category" --fields="name=string(255)"
and the new entity was created as expected, but I noticed that it generated some PHP code I'm not familiar with:
private $name=string(255);
and
public function setName=string(255)($name=string(255))
I've never seen before the string(255) when declaring a variable nor a function, and when I run
php app/console doctrine:generate:entities AppBundle
It throws an Fatal Parse Error on those lines. Removing the string(255) thing solves it. So, is it fine that Doctrine adds that code and my PHP interpreter's configuration is wrong? Doctrine shouldn't be adding that code or should I remove it after generating the entities? and finally, removing that code won't have consequences in the future?
Thanks,
If you look at the documentation for doctrine:generate:entity, you'll see that the format for declaring the fields looks actually like this:
... --fields="name:string(255)"
So you have to use a : (colon) to separate the field name of the type instead of an equal sign.

Unknown database type geometry requested error in doctirne:mapping:import for Symfony2

I'm getting the following error while running the doctrine:mapping:import command in Symfony2. I'm using SQL Server 2012 even though the error says " 2008Platform may not support it".
[Doctrine\DBAL\DBALException]
Unknown database type geometry requested, Doctrine\DBAL\Platforms\SQLServer
2008Platform may not support it.
My database configuration look like this:
doctrine:
dbal:
driver: pdo_sqlsrv
host: localhost
port: 1433
dbname: test
user: user
password: password
charset: UTF8
I have also tried setting the mapping type to string. But it gives the same error.
When I try the command using MyMainBundle string --force. I get this error:
[Doctrine\ORM\Tools\Export\ExportException]
The specified export driver 'string' does not exist
I have used the driver here for php.
Based on the error message one of the tables for which you're trying to import the schema contains a column of type geometry. Afaik Doctrine2 does not support the Geometry type out of the box (hopefully that will change soon).
One thing that might help would be to create a custom mapping type, as described here: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html
Another option you could try is the doctrine-spatial bundle, found here: https://github.com/djlambert/doctrine2-spatial
Not sure if this works with a mssql-based server though...
I've just met similar issue which was caused by already existing tables in public schema (tables like geography_columns created during PostGIS installation).
As a solution I skip using schema "public" for my app and store tables/entities in e.g. "main" schema..

Symfony2 generate entities error

I'm trying to generate entities from existing tables in database, I keep getting the same error in a particular entity, which is imported from a second database (or entity manager), but I re-created this table in main database to use the same entity manager and get the same error, so I'm lost about what is happening.
This are my commands to generate it:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --filter="Product" --em=mysecondaryem
(BTW, is there a way to force exact filter? I only need Product)
Which seems to be ok:
Processing entity "ProductSold"
Processing entity "Product"
Exporting "yml" mapping information to...
Then
php app/console doctrine:mapping:import MyShopProductBundle annotation --em=mysecondaryem
Which is weird, as it is logging information about all other tables existing in this db but it's only generating the corresponding to "Product" as filtered (only the files ProductSold.php and Product.php do really exist):
Importing mapping information from "mysecondaryem" entity manager
> writing C:\mysite\src\MyShop\ProductBundle/Entity/ProductSold.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Family.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Category.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Item.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Stock.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Product.php
Then, in the third step, I get an error:
php app/console doctrine:generate:entities MyShopProductBundle --no-backup
Generating entities for bundle "MyShopProductBundle"
[RuntimeException]
Bundle "MyShopProductBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name
As I sayed, I tried omitting secondary entity manager (replicating tables in my first database) and I get the same error.
You've verified that C:\mysite\src\MyShop\ProductBundle/Entity/Product.php has been created, but have you also checked that it actually contains mapped entities ?
Ok, I found the error, I was missing --force parameter, first step command should be:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --force --filter="Product" --em=mysecondaryem

Resources