Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:seed will truncate table #246

Closed
moxx opened this issue Feb 3, 2013 · 2 comments
Closed

db:seed will truncate table #246

moxx opened this issue Feb 3, 2013 · 2 comments

Comments

@moxx
Copy link

moxx commented Feb 3, 2013

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

@taylorotwell
Copy link
Member

Fixed.

@jhonatan6794
Copy link

Estoy perdido, i lost @taylorotwell [Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a t
able referenced in a foreign key constraint (laravel5_1.posts, CONSTRAI
NT posts_user_id_foreign FOREIGN KEY (user_id) REFERENCES laravel5_1.
users (id)) (SQL: truncate users)

joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
joelharkes pushed a commit to joelharkes/framework_old that referenced this issue Mar 7, 2019
Self service ux change + feedback implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants