[BUG] Typed propert $foreignReferencedTable must not be accessed before initialization
marlieer opened this issue · 3 comments
Package Version
What version are you running?
4.1.0
Database Version
What database driver are you using? And what version is that database?
MySQL. mariadb:10.2 image
Describe the bug
A clear and concise description of what the bug is.
I'm running php 7.4. After requiring and publishing this package according to the package docs, I run it via php artisan generate:migrations
. From there, I get the following error:
Typed property LaravelMigrationGenerator\Definitions\IndexDefinition::$foreignReferencedTable must not be accessed before initialization
php artisan generate:migrations
Using connection mysql
Using /app/tests/database/migrations as the output path..
Error
Typed property LaravelMigrationGenerator\Definitions\IndexDefinition::$foreignReferencedTable must not be accessed before initialization
at vendor/bennett-treptow/laravel-migration-generator/src/Definitions/IndexDefinition.php:74
70▕ * @return string
71▕ */
72▕ public function getForeignReferencedTable(): string
73▕ {
➜ 74▕ return $this->foreignReferencedTable;
75▕ }
76▕
77▕ /**
78▕ * @return array
+18 vendor frames
19 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
To Reproduce
Please include any stack traces and applicable .env / config changes you've made
Stack trace:
[2022-01-24 19:29:21] local.ERROR: Typed property LaravelMigrationGenerator\Definitions\IndexDefinition::$foreignReferencedTable must not be accessed before initialization {"exception":"[object] (Error(code: 0): Typed property LaravelMigrationGenerator\\Definitions\\IndexDefinition::$foreignReferencedTable must not be accessed before initialization at /app/vendor/bennett-treptow/laravel-migration-generator/src/Definitions/IndexDefinition.php:74)
[stacktrace]
#0 /app/vendor/bennett-treptow/laravel-migration-generator/src/Helpers/DependencyResolver.php(37): LaravelMigrationGenerator\\Definitions\\IndexDefinition->getForeignReferencedTable()
#1 /app/vendor/bennett-treptow/laravel-migration-generator/src/Helpers/DependencyResolver.php(21): LaravelMigrationGenerator\\Helpers\\DependencyResolver->build()
#2 /app/vendor/bennett-treptow/laravel-migration-generator/src/GeneratorManagers/BaseGeneratorManager.php(105): LaravelMigrationGenerator\\Helpers\\DependencyResolver->__construct(Array)
#3 /app/vendor/bennett-treptow/laravel-migration-generator/src/GeneratorManagers/BaseGeneratorManager.php(87): LaravelMigrationGenerator\\GeneratorManagers\\BaseGeneratorManager->sortTables(Array)
#4 /app/vendor/bennett-treptow/laravel-migration-generator/src/Commands/GenerateMigrationsCommand.php(80): LaravelMigrationGenerator\\GeneratorManagers\\BaseGeneratorManager->handle('/app/tests/data...', Array, Array)
#5 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): LaravelMigrationGenerator\\Commands\\GenerateMigrationsCommand->handle()
#6 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#7 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#8 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#9 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#10 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#11 /app/vendor/symfony/console/Command/Command.php(298): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#13 /app/vendor/symfony/console/Application.php(1005): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /app/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(LaravelMigrationGenerator\\Commands\\GenerateMigrationsCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 /app/vendor/symfony/console/Application.php(171): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 /app/vendor/laravel/framework/src/Illuminate/Console/Application.php(94): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 {main}
"}
Expected behavior
A clear and concise description of what you expected to happen.
I expect migrations to be generated.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
I upgraded from php 7.3.7 to php 7.4 to use this package. Is there a better php version to use? Some google searches show that "Typed properties" were added into php 7.4
@marlieer Do you have any circularly referenced tables being exported? Could you share any reproducible database SHOW CREATE TABLE {table name here}
for me to see?
Closing issue without further bug report data to be tested with.
@bennett-treptow can u check with this ;)
CREATE TABLE `users` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`age` bigint unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`deleted_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `chk_age` CHECK ((`age` > 0))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;