Doctrine Attributes Type Inet in PostgreSQL - php

It may be just a bug in Doctrine custom types. I didn't find anything about this problem.
I'm using symfony 6.2 and I generate migrations with doctrine attributes.
I've created my own type "Inet" for doctrine. I completed all commands for generation from attributes migration of migration and migrated this migration.
But if I do a command
php bin/console doctrine:migration:diff
again I see that doctrine is see it like a diff from current schema
$this->addSql('ALTER TABLE email_confirm ALTER ip TYPE inet');
But there is already Inet in postgreSQL and right attributes for doctrine

Related

Doctrine migration is not generating migration version for one particular entity

I am using symfony and in that I am trying to generate new migration version with the following command:
app/console doctrine:migration:diff
it is genrating new migration file but there is a table in Entity directory called transaction for this particular table i am not able to generate migration or can say the table is not being created in database. Please help me generating migration / table by script only. I don't want to generate it manually.
Thanks
Use this command to generate a migration file which will be get created in migration\ folder
php app/console make:migration
Then hit this command to reflect your entity into the database
php app/console doctrine:migration:migrate
To check you current migration status and track hit this command
php app/console doctrine:migration:status
Install symfony CLI for ease from
https://symfony.com/download
I just had the same problem: migration wasn't getting generated for a specific entity.
After a while I found out it was because of my Doctrine Cache.
I cleared the cache pool and could generate my migration properly.

Difference between Symfony/Doctrine commands "make:migration" and "doctrine:migrations:diff"

Is there a differences between the Symfony console command make:migration and doctrine:migrations:diff?
There is no difference between these two commands.
make:migration is simply a Symfony provided wrapper for the Doctrine command.
You can run either to the exact same effect. But the symfony one requires that you have the Symfony Maker bundle, which otherwise it not required.
make:migration will create empty file for you so you can write your custom migration
doctrine:migrations:diff will compare your current database schema with entities mappings and if there is difference then it will create migration so you can update you database schema to reflect your entities mappings

Unknown column type "json" requested running Doctrine 2 migrations

Some background about my application:
ZF2 application
doctrine/dbal v2.5.12
doctrine/orm v2.5.6
doctrine/migrations v1.5.0
Problem: if I run a command migrations:diff to generate migration from changes in my entity classes, I get the following exception:
[Doctrine\DBAL\DBALException] Unknown column type "json" requested.
Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap().
The issue is that doctrine/dbal version 2.5.x had no support for JSON fields in MySQL.
Bump the version of doctrine/dbal in your composer.json to ^2.6 and it should work. Make sure to check for compatibility-breaking changes in the release changelog
The problem was because old column in database had a comment (DC2Type:json). I changed it to (DC2Type:json_array) and it works.
Why this problem occur? While doctrine is calculating the DIFF between entity mappings with database columns and actual database columns, Doctrine parses MySQL column comment ((DC2Type:json)) and validates json type. Since from newer Doctrine versions, you must use json_array instead of json, Doctrine library throws an exception.

doctrine migrations 2 + zend framework 2 = is it possible?

I have used this guide http://www.jasongrimes.org/2012/01/using-doctrine-2-in-zend-framework-2/ and now I have a working Doctrine 2 + ZF2 software.
I use a versioning system and I want then use Doctrine MIGRATIONS tool to have a database migration system.
If I put on a shell ./doctrine-module orm:schema-tool:update it works correctly, but if I use a migration tools for example ./doctrine-module migrations:status the system give me an error:
[Doctrine\DBAL\Migrations\MigrationException]
Migrations namespace must be configured in order to use Doctrine migrations.
Which configurations are needs? Does DoctrineOrmModule support Doctrine migration?
I have found this for zf1 http://moxune.com/blog/2011/10/configure-doctrine-migrations-2-zend_config/
If you check the current Travis CI CLI test for DoctrineORMModule you will notice that there's a --configuration parameter pointing to an XML configuration, as described in Doctrine Migrations documentation. Setting that parameter and having DoctrineORMModule configured correctly should allow you to use the CLI.

Is it possible to run the task "symfony doctrine build --all" on only one table?

If I run the folowing task, it builds everything and wipes out the database:
php symfony doctrine build --all
I would like this task to run only for the new table that I've put in schema.yml
Is it possible ?
I think you should use migration for that.
First, you need to restore the initial state (when schema, model and db are in sync). Remove your changes form schema.yml rebuild your model php symfony doctrine:build --all-classes and import the original database.
After that make your changes in schema.yml and run these commands:
php symfony doctrine:generate-migrations-diff
php symfony doctrine:migrate
php symfony doctrine:build --all-classes

Categories