I have just installed symfony2 and I used this statement
php app/console doctrine:schema:create
When I see the database table, there is only one table and that is for my entity.
I can't see any base tables.
Is that normal??
It is absolutely normal. Symfony is a framework, it doesn't need any database tables. All settings for it are saved in configuration files which can be found in /app/config directory (application config files). And config files for bundles can be found in bundle_dir/Resources/config
Database is for your entities only. Have in mind that if you use "Doctrine Migrations", it will indeed create one database table called "doctrine_migrations".
The framework itself hasn't got any "base tables". It persists your entities only.
Related
I have the database entities in my Symfony application, I have created another table in the database and I want to download it as an entity in my program. When I execute the following line I get that there are tables that already exist.
php bin/console make:migration
How can I update the entities and create only the ones that are not there?
I have an application which is using Entity Framework 6 in order to interact with a SQL Server database. I have several migrations files due to the evolution of the application.
Now, I'd like to add the possibility to choice between a SQL Server database and a PostgreSQL database with keeping the same entity model.
When I apply the migrations files on SQL Server, all is ok.
But when I apply the same migrations files on PostgreSQL, it says that the database does not match the entity model and I have to generate a new migration file.
If I generate a new migration file, I see that it want to remove the property unicode on all string columns. I think it's because on PostgreSQL the type varchar (character varying) is able to store unicode and non unicode characters.
If I apply this migration file on PostgreSQL, all is ok now. But if I apply it on SQL Server, it say that the database does not match the entity model => columns varchar has been replaced per nvarchar.
I thought that the migrations files was able to adapt to the provider but apparently not.
For information, the property unicode is manage like that in the onModelCreating method :
modelBuilder.Entity<MyTable>()
.Property(e => e.ColumnName)
.IsUnicode(false);
So, my question is, do I have to manage different migration files depending on provider, knowing that I want to keep the same entity model ? If yes, how can I do this ?
Thanks a lot for your help
I have found a solution, I'm not sure it's the best but it's working.
In order not to be annoy anymore, I've created a batch migrations files per provider.
For that I've created one configuration per provider with specifying a specific context key and a different folder containing the migrations files.
This permits to switch between the different configurations depending of the current provider.
I am working on a desktop application that uses a local installation of MySQL to store data across multiple schemata. My goal is to use SymmetricDS to transfer those schemata to an Oracle database on a different machine.
So far I managed to set up a slave node residing on the desktop computer and a master node residing on some server. Using a .properties file in the engine directory, I also successfully transfer data from a single schema and table to the Oracle DB.
The problem I am now facing is that my application will create and possibly delete schemata on the fly.
Does that mean I will have to maintain a .properties file for each schema and somehow implement a wrapper for the symadmin command to register the corresponding engines?
Or is there maybe a better way?
You should able to adjust configuration on the fly. The sym_trigger table has a reference to schema for each table. If the database user SymmetricDS uses has access to newly created schemas (database) then SymmetricDS should be able to create new triggers dynamically that are in new databases. No restart needed.
I have several tables that I have created through migration. Then, what happens if I change the table structure directly from PHPMYADMIN without using migration? What if my backend team pulls my project, then runs the "php artisan migrate" command. Is the database on my backend team the same as the database that I have?
If you make changes through phpMyAdmin, these will only be visible to you. You should change the migrations, or if you can't change the original because you don't want to reset the database, you should create a new migration to alter the table. Check the documentation for altering tables here: https://laravel.com/docs/5.7/migrations#modifying-columns
What is the difference between
symfony doctrine:generate-migrations-db
and
symfony doctrine:generate-migrations-models
I can't notice any difference: I've tried with tables IN DB, NO schema.yml and NO models, both of them have no effect. No migrations generated.
I've tried with tables IN DB, GENERATED schema.yml and NO models, both of them have no effect. No migrations generated.
And lastly I've tried with tables IN DB, GENERATED schema.yml and GENERATED models, now both of them generate the same migrations classes :|.
Can't really understand the difference. Or at least, what is the best way to start using migrations considering all scenarious: having models, but no DB and having DB, but no models.
Thanks.
Given an existing database with 1+ tables, running
./symfony doctrine:generate-migrations-db
will result in migration files being created for each table. Similarly, given a directory like /lib/model/doctrine filled with pre-existing model classes, running
./symfony doctrine:generate-migrations-models
will result in migraiton files being created for each model.
With tables in the database, with or without schema.yml contents, and no models in lib/model/doctrine, you just need to ensure you're database.yml file has credentials to correctly connect to your database.
Once you figure out the problem with your migrations files not generating, what I would do is something like to get started with migrations.
Generate a fresh schema from your existing database with ./symfony doctrine:build-schema
Manually clean up the schema file, and re-establish your relations you're already got existing in your model files (if any).
Reconfigure config/databases.yml to point to a new blank database
Build migrations with ./symfony doctrine:generate-migrations-diff. This will create migrations based on your schema file to bring your (blank) database up to date
Run ./symfony doctrine:migrate and watch for errors. Fix them by fixing your schema file. Delete the migrations created in Step 4. Flush your databse ./symfony doctrine:drop-db && ./symofny doctrine:build-db and go back to Step 4. Continue until you're schema generates a clean set of migrations files that can run without error.
Rebuild your models with ./symfony doctrine:build --model --forms --filters
Now you have a clean schema.yml file, clean migrations that can bring a blank database up to date, and models that directly relate to your schema.yml file and database.
When you want to make a new change to your database, it's now as simple as
Make the desired change in your schema.yml
Run ./symfony doctrine:generate-migrations-diff
Manually review the generated migrations
Run ./symfony doctrine:migrate to make sure the migrations run without error
Rebuild your model, forms, and filters ./symfony doctrine:build --model --forms --filters
Going through this process can be frustrating at times, but it's something you only have to do once to create a really good based to build upon.