The course is built on Symfony 4, but the principles still apply perfectly to Symfony 5 - not a lot has changed in the world of relations!
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.7.2
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.4
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.0.4
"symfony/console": "^4.0", // v4.0.14
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.14
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.4
"symfony/web-server-bundle": "^4.0", // v4.0.4
"symfony/yaml": "^4.0", // v4.0.14
"twig/extensions": "^1.5" // v1.5.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"fzaninotto/faker": "^1.7", // v1.7.1
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.4
"symfony/dotenv": "^4.0", // v4.0.14
"symfony/maker-bundle": "^1.0", // v1.4.0
"symfony/monolog-bundle": "^3.0", // v3.1.2
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.0.4
"symfony/stopwatch": "^3.3|^4.0", // v4.0.4
"symfony/var-dumper": "^3.3|^4.0", // v4.0.4
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.4
}
}
11 Comments
"Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes"
I've got this error when I tried to migrate. The migration executes just fine if I remove "unique=true" from the annotation. Any ideas how to fix it? It looks like a bug in Symfony (my version is 4.0.14).
Hey boykodev!
Try making that column length a little shorter - like length=180. The problem is InnoDB + using the utf8mb4 encoding. It ultimately tries to make a key length that is longer than is supported. If you're able to shorten the field length, it also makes the key a bit shorter.
Here is a discussion about that, from FOSUserBundleL https://github.com/FriendsO...
I'm a little surprised I didn't have that issue during this tutorial - I have seen it in other places.
Cheers!
Thanks for this hint. I ran into the same problem. Shortening the length to 180 worked for me. I edited the VersionXXXXX.php file within the Migrations folder and executed the php bin/console doctrine:migrations:migrate afterwards without errors.
this solution works fine
That problem occurs when you are on MySql 5.6 and using "utf8mb4" charset, if you upgrade to MySql 5.7 then you won't have that problem again.
Cheers!
Hey guys, what's up!
I often ask myself, is there more simple way to create some dummy data to test applications instead of Fixtures? Do not misunderstand me, but I find Eloquent/Factory more friendly (simple) and flexible than Fixtures (Doctrine's or Codeception's, I've been used both). Do doctrine has the same or an analog?
Hey David B.!
I couldn't agree more - I've always thought Doctrine fixtures were clunky - and it's been on my list for a long time to improve it. But, that's *also* why we added our own mini-fixture system on top of Doctrine in this tutorial. I think we finish/user that system in this video - https://symfonycasts.com/sc... - you can see how you can create a collection of (for example) Article objects by using fake data inside a callback. You don't return an array like an Eloquent factory, but that's due to the way Doctrine is built - you tend to deal more directly with your objects vs returning arrays and having Eloquent magically put those onto your objects (it does look good though in the factory)!
Does the system we create in this tutorial somewhat address what you're thinking? I'd love to know!
Cheers!
Thanks for your answer weaverryan ! I'm not sure that Fixtures are completely clear for me to use it without any problems, but I hope they will. The main misunderstanding point for me is generic types while getting a reference to relation, saving references and their naming.
I think we should pass it (
$className . '_') to it's own method which will return the reference prefix. This also could change in the future. BTW, we don't need to pass the$entityManageras an argument and to the callback because we an use$this->manager, am I right?Hey David B.!
Sorry for my slow reply!
I didn't quite understand what you mean by this part. Could you tell me more? If you fully create the
BaseFixtureclass like we do on that tutorial, you should never need to worry about setting references (it's done in the background for you when you use the$this->createMany()method) and you can use$this->getRandomReference()to fetch a random reference. But if you find ways to improve the data for your own use, please do :).Correct! They are exactly the same object - so you can use either. Using
$this->manageris just easier in this case (because you don't need to pass anything to the callback directly).Cheers!
I didn't know my mistake or not, but if I didn't write: use Doctrine\Bundle\FixturesBundle\BaseFixture;
I can't do doctrine:fixtures:load
The autoloader expected class "App\DataFixtures\TagsFixtures" to be defined in file "\vendor\composer/../../src\DataFixtures\TagsFixtures.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
Hey Student,
This error looks like you have namespace problems. Please, open "src\DataFixtures\TagsFixtures.php" file and make sure it has a proper namespace i.e. "App\DataFixtures\TagsFixtures".
Cheers!
"Houston: no signs of life"
Start the conversation!