all doctrine migration alter same table and no change in db - symfony

On symfony 4.3 (doctrine 2.10)
all migrations contain the same lines, even without entity changes...
example:
ALTER TABLE file_master CHANGE file_name file_name VARCHAR(255) DEFAULT NULL')
do you have the same issue?
Tkx.
Cédric

I had the same issue with mariadb database. I changed database version in doctrine.yaml file and it worked for me:
doctrine:
dbal:
server_version: 'mariadb-10.4.7'
I took server version from phpMyAdmin. Before this value was '5.7'

This might be linked to this particular issue : https://github.com/doctrine/dbal/issues/3006 in Doctrine.
One workaround that seem to work is to make sure that if any of your entity's field has an option parameter containing default, it should be equal to 1 like this, and not be just a key (options={"default"}):
#ORM\Column(name="field", type="integer", length=8, options={"default": 1 })
See https://github.com/doctrine/orm/issues/6845
Hope that helps

If you are using MariaDB here is an article about that issue: https://marenkay.com/post/symfony-doctrine-mariadb/
I've solved it by simply removing server_version from the doctrine config completely. Otherwise you have to specify the mariadb version, for example "mariadb-10.3.18" instead of the mysql version.

Related

doctrine schema update wants to drop migration_verions table symfony

When I try to run doctrine:schema:update --complete --dump-sql on a Symfony dockerized application, the output is showing below:
ALTER TABLE offer DROP FOREIGN KEY FK_29D6873EC1EA42F3;
DROP TABLE doctrine_migration_versions;
I expect that the table migration_versions should not be deleted!
I am using mariadb:10.9.4 mysql
Add schema_filter to your doctrine.yaml
doctrine:
dbal:
url: '%env(DATABASE_URL)%'
schema_filter: "~^(doctrine_migration_versions$)~"
And try to launch the command without the --complete option
You can read better explanation on this on one of my old answer :
Symfony 5 - Doctrine with schema_filter not working

Symfony - Doctrine: migration with multiple schema failed

Environnement:
php 8.1
symfony 5.4
doctrine/dbal 3.3
doctrine/doctrine-bundle 2.7
doctrine/migrations 3.5.1
postgresql 14.4
My problem is the following;
We have a database containing several schema to separate the data useful to the system and those published directly to users.
We use of course the classic entity declaration with Symfony & Doctrine:
/**
* #ORM\Table(name="stats", schema="system")
* #ORM\Entity(repositoryClass="App\Repository\System\StatsRepository")
*/
class Stats
The problem is that when we delete a relation between the public schema and the system schema, the migration generated by the command bin/console doctrine:schema:update has an error when deleting the index.
Here is the migration generated:
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('DROP INDEX idx_2225600edc6d4b4b');
$this->addSql('ALTER TABLE system.stats DROP article_id');
}
The problem being that in deleting the index, the line forgets to specify that the index comes from the system schema.
We need:
$this->addSql('DROP INDEX system.idx_2225600edc6d4b4b');
We want to keep the bin/console doctrine:schema:update operation for updating the database, but this problem now forces us to use the migration system to change the drop index.
I know that the obvious solution would be to use the migration system (bin/console make:migration) but this implies some changes in the IC. That's why I'm wondering; have you ever had this problem? If yes, how did you solve the problem?

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..

Nothing to update "Doctrine"

I'm using Symfony2 with Doctrine to try and update a table schema. I was able to create the table. I was also able to populate the table. However after updating the comments in the Entity (I wanted some fields to become nullable), those changes did NOT get picked up.
I did create the entity with the "Annotations" option chosen. But when I added this line "nullable=true" to the Entity on the field imageName nothing happens. ie: when I run "./app/console doctrine:schema:update" I get the following output "Nothing to update - your database is already in sync with the current entity metadata."
Note, I have tried deleted the table via: ./app/console doctrine:database:drop --force and then recreating it via: ./app/console doctrine:database:create and then also ./app/console doctrine:schema:create but it STILL does not add my updated nullable field to imageName.
I was able to figure this out. I first of all created my entity "Foobar" using yml as the Configuration format. I then wanted to use "annotation" as the configuration format so I manually deleted the Entity folder (I only had one table created), however I did NOT delete the configuration yml in the Resources/config/doctrine/Foobar.orm.yml.
Thus when I created the entity again, this time using the annotation as the configuration format, it was still linking to the yml configuration. Removing that solved all the troubles.
I have however decided to stick to yml as I feel it is a little easier to read than the Doctrine Metadata found in the comments.
I had been stuck with this for almost 2 days. Removing all the file in /src/AppBundle/Resources/config/doctrine resolve my issue.
For me, the key was to clear Redis cache.
php app/console redis:flushdb
I has this problem too. Have you right annotation before class declaration?
/**
*
* #ORM\Entity <- this does the trick
*/
class MyEntityName
{
...
Check doctrine.yaml config file for orm mappings:
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
As you see here all entities should have prefix (namespace) App\Entity
You have to check your entities namespace, it should be App\Entity or whatever you want in config

Create Entities from existing DB

Newest Version Symfony2 and using MAMP on a MAC. Following command:
php app/console doctrine:mapping:convert yml ./src/Acme/DemoBundle/Resources/config/doctrine/metadata/orm --from-database --force
My Error:
[Doctrine\DBAL\DBALException]
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
Don't have any idea. What is wrong?
A connection to my db is working. Because I tried to create a table and the output was that the table exist.
Sorry, I missed it and here is the solution of my question.
http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool

Resources