Chapters
22 Chapters
|
2:28:56
|
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!
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!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.7", // v3.7.0
"doctrine/doctrine-bundle": "^2.7", // 2.7.0
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.12", // 2.12.3
"knplabs/knp-time-bundle": "^1.18", // v1.19.0
"pagerfanta/doctrine-orm-adapter": "^3.6", // v3.6.1
"pagerfanta/twig": "^3.6", // v3.6.1
"sensio/framework-extra-bundle": "^6.2", // v6.2.6
"stof/doctrine-extensions-bundle": "^1.7", // v1.7.0
"symfony/asset": "6.1.*", // v6.1.0
"symfony/console": "6.1.*", // v6.1.2
"symfony/dotenv": "6.1.*", // v6.1.0
"symfony/flex": "^2", // v2.4.5
"symfony/framework-bundle": "6.1.*", // v6.1.2
"symfony/http-client": "6.1.*", // v6.1.2
"symfony/monolog-bundle": "^3.0", // v3.8.0
"symfony/proxy-manager-bridge": "6.1.*", // v6.1.0
"symfony/runtime": "6.4.3", // v6.4.3
"symfony/twig-bundle": "6.1.*", // v6.1.1
"symfony/ux-turbo": "^2.0", // v2.3.0
"symfony/webpack-encore-bundle": "^1.13", // v1.15.1
"symfony/yaml": "6.1.*", // v6.1.2
"twig/extra-bundle": "^2.12|^3.0", // v3.4.0
"twig/twig": "^2.12|^3.0" // v3.4.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.2
"symfony/debug-bundle": "6.1.*", // v6.1.0
"symfony/maker-bundle": "^1.41", // v1.44.0
"symfony/stopwatch": "6.1.*", // v6.1.0
"symfony/web-profiler-bundle": "6.1.*", // v6.1.2
"zenstruck/foundry": "^1.21" // v1.21.0
}
}
8 Comments
Hello
I somehow messed one of my tables badly, so when I run Symfony console make:migration and all my files are committed (no changes) this migration is generated:
My Questions:
symfony console doctrine:migrations:diffto generate the current SQL and then remove all migrations except the first one, and in the "up" method to add the generated code. However it didn't mention what should one add in the "down" method. Can this approach be used as a way to resolve messed up migrations?Hi
I managed to resolve my issues, and I am posting the solution here in case that someone has similar issue(s).
I solved my issues in 3 steps:
nullable:truein the#[ORM\Column(length: 255)]attribute that I had, so my attribute now looks like this:#[ORM\Column(length: 255, nullable:true)]Cheers
Hey @t5810!
Thanks for posting that! You got the correct solution :). I'm not sure how your database got into the state it was, but you did perfectly to change your options on your entity and THEN generate a migration to keep your database in sync.
Anyway, good job and keep going!
We changed $votes property never to be null. So can we remove "?" in getVotes method (or this will provide errors during for example form saving)? And the same question about getCreatedAt method
Hey @Dima
Yes, you're right. Since those fields are not nullable anymore, you can do that refactoring, but as you said, if you are using Symfony Forms to create new
VinylMixrecords, then you can't remove it from the$votespropertyCheers!
concerning default values...
Am I right to understand that the way you've shown here (i.e. creating the entity > altering the code to insert defaults > not migrating the code changes), the table would still accept
nullvalues, but no value would ever benullbecause I changed the code?If so, how could I make the table no longer accept
nullvalues? Should I run thesymfony console make:migrationcommand again? Or isn't there a way to do this once it's been set as nullable?...? Can anybody help me with the above question?
Hey!
Sorry we missed your original question somehow! Not cool!
Not quite :). There are two totally independent systems going on:
A) By adding the defaults in PHP, it means that the properties on the PHP object will never been
null. So, you've got that correct.B) But, whether or not the database will accept
nullvalues is determined by something else: thenullable: option onORM\Column. For example, you could have:In this case, in PHP, the
nameproperty could never benull. But, technically, you COULD insert a row into the database with anullvalue (and yes, if you changednullable: false, you would need to run a database migration for that).So, to answer this question:
The answer is: if you want a column in your table to NO accept
nullvalues (i.e.to explode with an error ifnullis sent), usenullable: falseon that property (or omit thenullableoption entirely, becausefalseis the default value fornullable).Let me know if that clears things up... or if I'm still being confusing :).
Cheers!
"Houston: no signs of life"
Start the conversation!