Skip to content

db:seed will truncate table #246

Closed
Closed
@moxx

Description

@moxx

Hi,

i have updatet my laravel 4 and was running in an db:seed problem in:

laravel/framework/src/Illuminate/Database/Seeder.php:62
$connection->table($table)->truncate();

b897fd1

Thats the death if you working with a bunch of foreign key constrains.
Why you dont leave the delete? Is it for the AI reset?

In my case db:seed ends in an ->

[Exception]                                                                                                                                                                                       
  SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (`dbname`.`table2`, CONSTRAINT `fk_table2_table1  
  ` FOREIGN KEY (`t1colum1`) REFERENCES `dbname`.`table1` (`colum1`)) (SQL: truncate `table1`) (Bindings: array (                                                                                  
  )) 

Maybe its possible to give the seed file options for they should leave, delete or truncate the table/data.

 array(
    'table' => 'mytable',
    'delete' => 'false/true/truncate',
    #is the truncate for reset AI maybe this also an possible way to reset correct
    'resetAI' => 3000, //ALTER TABLE foo AUTO_INCREMENT = 3000

short fix for all with the same troubles is to replace

#in file
laravel/framework/src/Illuminate/Database/Seeder.php:62
#the
$connection->table($table)->truncate();
#with
$connection->table($table)->delete();

thanks for your work,

ng
moxx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions