Comments (6)
What do your database tables look like? Your having some foreign key constraint fail probably
from testdummy.
Thanks @ddelnano
but I don't think my database is wrong coz I can make it work with normal database seeder. (not with model factory). for example. when I save [ user_id ] to posts table it saves like [ user_id = factory:App\User ]. I'm on Laravel v 5.1.16.
from testdummy.
Unless you show the tables and migrations we won't be able to tell.
from testdummy.
hi @ddelnano
I have Goods table & Imports table and others table similar like that.
// Goods Schema ...
Schema::create('goods', function(Blueprint $table) {
$table->increments('id');
$table->integer('import_id')->unsigned();
$table->foreign('import_id')->references('id')->on('imports');
$table->integer('car_type_id')->unsigned();
$table->foreign('car_type_id')->references('id')->on('car_types');
$table->integer('brand_id')->unsigned();
$table->foreign('brand_id')->references('id')->on('brands');
$table->timestamp('model_year');
$table->string('engine_power');
$table->string('consignor_name')->nullable();
$table->decimal('unit_price', 12, 2); // 100,000,000
$table->integer('permit_type_id')->unsigned();
$table->foreign('permit_type_id')->references('id')->on('permit_types');
$table->string('port_of_landing');
$table->integer('import_method_id')->unsigned();
$table->foreign('import_method_id')->references('id')->on('import_methods');
$table->timestamps();
});
// and Import Table ....
Schema::create('imports', function(Blueprint $table) {
$table->increments('id');
$table->integer('voucher_no');
$table->timestamp('licence_date');
$table->decimal('fees', 12, 2); // 100,000,000
$table->string('licence_no');
$table->timestamp('last_date_import');
$table->integer('registration_no');
$table->integer('hs_code');
$table->timestamps();
});
Bty thanks for ur time.
And my full error message is...
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`account
ing`.`goods`, CONSTRAINT `goods_import_id_foreign` FOREIGN KEY (`import_id`) REFERENCES `imports` (`id`)) (SQL: insert into `goo
ds` (`import_id`, `car_type_id`, `brand_id`, `model_year`, `engine_power`, `consignor_name`, `unit_price`, `permit_type_id`, `po
rt_of_landing`, `import_method_id`, `updated_at`, `created_at`) values (factory:App\Import, factory:App\CarType, factory:App\Bra
nd, 2015-09-14 13:37:03, 1032cc, Priscilla Reichert MD, 1316, factory:App\PermitType, Israel, factory:App\ImportMethod, 2015-09-
14 13:37:03, 2015-09-14 13:37:03))
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`account
ing`.`goods`, CONSTRAINT `goods_import_id_foreign` FOREIGN KEY (`import_id`) REFERENCES `imports` (`id`))
And my database seeder file is
$this->call('ImportsTableSeeder');
factory(App\Good::class, 50)->create();
from testdummy.
Yea so the import_id is not getting set when you are trying to seed the database you need in your factory definition
$factory('Good`, [
// other columns....
'import_id' => 'factory:Import'
]);
from testdummy.
Yeah I've test with
'import_id' => 'factory:Import',
// and
'import_id' => 'factory:App\Import',
both not work.
from testdummy.
Related Issues (20)
- `$faker->optional()` is not getting called foreach transaction HOT 3
- Issue with using strings as primary id HOT 1
- Create Models from json/array
- Call to undefined method User::fill() HOT 2
- Factory::build should take times() into account HOT 2
- Create factory extending/overriding an existing factory's attributes HOT 1
- More then one row beeing adding to relational models
- Getting faker not found error running through behat
- Problem with attribute casting
- Use factories for not Eloquent model HOT 8
- Can't use array attributes
- fakerphp/faker downgraded when installing laracasts/testdummy
- Is unique() supported? HOT 7
- Object of class Closure could not be converted to string HOT 2
- Could not locate a factory HOT 9
- unique() in user Closures
- Relationship attributes not being added to model instance before saving? HOT 5
- Ability to specify relation create new or use existing HOT 8
- Faker Localization HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testdummy.