Chapters
27 Chapters
|
2:45:18
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
22.
When a Migration Falls Apart
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.3", // v3.3.0
"composer/package-versions-deprecated": "^1.11", // 1.11.99.3
"doctrine/doctrine-bundle": "^2.1", // 2.4.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.1.1
"doctrine/orm": "^2.7", // 2.9.5
"knplabs/knp-markdown-bundle": "^1.8", // 1.9.0
"knplabs/knp-time-bundle": "^1.11", // v1.16.1
"pagerfanta/doctrine-orm-adapter": "^3.3", // v3.3.0
"pagerfanta/twig": "^3.3", // v3.3.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.1
"stof/doctrine-extensions-bundle": "^1.4", // v1.6.0
"symfony/asset": "5.3.*", // v5.3.4
"symfony/console": "5.3.*", // v5.3.7
"symfony/dotenv": "5.3.*", // v5.3.7
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/framework-bundle": "5.3.*", // v5.3.7
"symfony/monolog-bundle": "^3.0", // v3.7.0
"symfony/runtime": "5.3.*", // v5.3.4
"symfony/stopwatch": "5.3.*", // v5.3.4
"symfony/twig-bundle": "5.3.*", // v5.3.4
"symfony/validator": "5.3.*", // v5.3.14
"symfony/webpack-encore-bundle": "^1.7", // v1.12.0
"symfony/yaml": "5.3.*", // v5.3.6
"twig/extra-bundle": "^2.12|^3.0", // v3.3.1
"twig/string-extra": "^3.3", // v3.3.1
"twig/twig": "^2.12|^3.0" // v3.3.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.0
"symfony/debug-bundle": "5.3.*", // v5.3.4
"symfony/maker-bundle": "^1.15", // v1.33.0
"symfony/var-dumper": "5.3.*", // v5.3.7
"symfony/web-profiler-bundle": "5.3.*", // v5.3.5
"zenstruck/foundry": "^1.1" // v1.13.1
}
}
10 Comments
I am using MariaDb 10.1.14 wtih docker-compose and a curious thing happens: the database accepts 0000-00-00 00:00:00 and the migration does not fail )-: So, ironically, here I am complaining because -- it works! Just kidding. I will pretend it fails and keep following the program.
Hey Elliott!
> So, ironically, here I am complaining because -- it works!
Haha, sorry! :D
Thanks for this tip! Yeah, it may depend on the DB provider you're using, and sometimes even on its version. Even if it works with zeros... you still may want to fix it in the migration to avoid that weird date in your data :)
Cheers!
The issue with the migration editing is that the result depends at which moment you did your commit(s). In my case, the fix seemed to work, but the home page was stuck with an error.
So what I did is a git reset and go on without the ManyToMany episode that does not work, and go directly with the extra QuestionTag entity.
I still wonder how to get out of this when you already have data in the database... Perhaps the solution is to edit the migration table to sync it with the migrations we want to keep inside Symfony.
Anyway, for my own projects, I have chosen to set entries to be nullable (and test if it is null in PHP)
Hey Francois,
Hm, if you already have some data in your DB and it does not work for you with simple Doctrine migration - you may want to create separate new tables for that and write a Symfony "migration" command and migrate all the data manually in it - you have much more power and flexibility in the Symfony commands.
I hope this helps!
Cheers!
you could just delete the 2 first lines in the migration
$this->addSql('ALTER TABLE question_tag DROP FOREIGN KEY FK_339D56FB1E27F6BF');$this->addSql('ALTER TABLE question_tag DROP FOREIGN KEY FK_339D56FBBAD26311');and put them back once the migration is executed.
following your solution you already altered the data that already exists in your production environment
Hey @Wael-G,
Yes, you can do that but I prefer to put any queries I want to rollback in the
down()method of the migrationCheers!
Why don'y set default value?
`
/**
*/
private \DateTimeImmutable $taggedAt;
`
The migration generate this colum as:
<br />ADD tagged_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL<br />Hey Jesús G.
I'd say to have more control over timezones. Your app will have full control of date settings, so it will be easier to maintain and develop your app =)
Cheers!
regarding cl 2:49
youre going to get fed up with my comments!
but...
as mysql now supports transactions, is there any way to get the migrations bundle to take that into account and use it? Like Pgres?
or is there some reason that cant be done?
Hey Matt,
Good question! I suppose it's possible, but I've never tried it :) Please, take a look at "transactional: true" option of the bundle, see docs for more info: https://symfony.com/bundles... - it seems like something you're interested in.
I hope this helps!
Cheers!
"Houston: no signs of life"
Start the conversation!