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

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

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.

Masters table not found in database

I have an issue with laravel.
I have created a database named billing and connection is working fine for all tables. Now I created a new table named as masters. When I'm using this table then it is showing error base table or view masters not found
How can I resolve this issue?
This is usual for beginners. I have a few hints:
You might want to manually check the database, outside of Laravel, to
be sure the table has not been add.
Sometimes, you might just have misspelt the table name.
Did you forget to run the migration? If so, you need to run the
migration to add the table to the database. You can simple use php
artisan migrate on the command line.
If all these don't resolve it, dump you autoload files with composer and rerun your migration. You can use composer dumpautoload and then php artisan migrate:refresh
To create a migration, use the make:migration Artisan command:
php artisan make:migration create_masters_table
The new migration will be placed in your database/migrations directory.
You can use Laravel schema builder to expressively create and modify tables.
To run all of your outstanding migrations, execute the migrate Artisan command: php artisan migrate

Laravel migration vs model creation

Is
php artisan make:model Test -m
equivalent to
php artisan make:migration create_tests_table --create=tests
?
Does make:model -m create a tests table?
In php artisan make:model Test -m, The -m flag will create a migration file for that model.
In php artisan make:migration create_tests_table --create=tests, the --create flag is the name of the table that will be created.
So yes, the -m option will create a migration file with a name like TIMESTAMP_create_tests_table.php
Update
If you find yourself in a situation when you doubt about commands, you can always run a command like this form your terminal: php artisan help make:model. You'll see an overview with some explenation about the extra options of that specific command.
No they are not equivalent; they are very different. One is creating a model AND also creating a migration while the other is just creating a migration (both migrations include a table called tests). Bear in mind that creating a model and creating a table are not the same thing. From the docs: "The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table."
https://laravel.com/docs/5.8/eloquent#defining-models

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

How does one call the down method for a Doctrine migration in Symfony 1.2?

I am using Symfony 1.2 with the sfDoctrinePlugin.
I couldn't find any command to call the down method on a migration, neither the documentation suggests any related arguments to the existing doctrine migrate command.
What would be a way to rollback the migration I just ran successfully? Creating a new migration to undo is an option, but that is almost blasphemous and plainly stupid.
If you are at Migration Version N, then
./symfony doctrine:migrate N-1
will call the down method on the Nth migration.
You could also do
./symfony doctrine:migrate --down
as by the docu:
symfony doctrine:migrate [--application[="..."]] [--env="..."] [--up] [--down] [--dry-run] [version]
Just give the migration number you would like to migrate to and Doctrine will determine whether to call up or down. See the API docs for migrate in 1.2:
(integer) migrate($to = null, $dryRun
= false)
Perform a migration process by
specifying the migration
number/version to migrate to. It will
automatically know whether you are
migrating up or down based on the
current version of the database.
returns Version number migrated to
throws Doctrine_Exception

Categories