doctrine schema update wants to drop migration_verions table symfony - 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

Related

all doctrine migration alter same table and no change in db

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.

Doctrine make:migration unknown database type

I am trying to start using Doctrine, but I encountered a problem when I created entity through php bin/console make:entity, then I tried to make migration with php bin/console make:migration but I get this error message:
Uknown database type _int4 requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it.
I am using postgres 9.4 and doctrine 2.6
In symfony config/packages/doctrine.yaml you can just map the type to data type that you want.
doctrine:
dbal:
mapping_types:
_int4: string

Specify entity name while generating from existing database table symfony2

I've a database table users and I want to generate its entity in my symfony2 bundle KapCrudBundle.
I'm using the following commands:
php app/console doctrine:mapping:convert yml ./src/Kap/CrudBundle/Resources/config/doctrine/metadata/orm --from-database --force --filter=Users
php app/console doctrine:mapping:import KapCrudBundle annotation --filter=Users
php app/console doctrine:generate:entities KapCrudBundle
These all above commands working absolutely fine but I want to do the following things:
It's generating the entity Users.php and annotation file Users.orm.yml because my table name is users but I want the entity name and annotation files like User.php and User.orm.yml
Second thing is that it generates all entities again in the bundle but I want only the User entity to generate.
Regarding the 2nd question: you can simply specify the entity.
php app/console doctrine:generate:entities KapCrudBundle/Entity/User

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