ichtrojan / laravel-location

A simple Laravel Package to sort Countries, States and Cities
MIT License
205 stars 44 forks source link

Use truncate() instead of delete() to keep IDs consistent #24

Closed djunehor closed 4 years ago

djunehor commented 4 years ago

I think it's better to truncate the tables than use delete(); Using delete() will empty the table, but the autoincrement ID remains the same. So, next time the Seeder is run, IDs start counting from the last autoincrement instead of 1. This can lead to inconsistent data. Since all 3 tables are related, the IDs should remain the same irrespective of the number of times the seeders are run.

Another reason is that using delete() leaves the tendency for duplicates. The name column is not set to be unique. So, each time I run the seeder, an exact data is duplicated in the table.