mshoaibdev / laravel-country-states-city-seeds-migration

Laravel Seeds and Migration Files for Countries,States and Cities
106 stars 101 forks source link

Wrong id in CitiesTableSeeder #1

Open greggh opened 5 years ago

greggh commented 5 years ago

I know this hasn't had an update in 2 years, but if anyone is watching this or attempting to use it. It is actually great, but has 1 big error. In the CitiesTableSeeder, everything past this line:

array('name' => "'Abdul Hakim",'state_id' => 2728),

Every record from that one on to the end needs the state_id bumped +1. So The one here should be 2729.

kblycay commented 5 years ago

can it be the same ? array('name' => "Ventspils City",'country_id' => 120), array('name' => "Ventspils",'country_id' => 120),

omusovski commented 5 years ago

How did you go about doing that? I could go through and update them one by one but there are thousands of records. Is there a better way?

greggh commented 5 years ago

I did it by copying that out into a text file and processing it at a command line with a bunch of awk and sed, so I could do it in bulk. I don't have that code anymore to share, sorry!

omusovski commented 5 years ago

Thanks for the reply! I figured out a different way to do it. I added this line of code to the end of CitiesTableSeeder.php:

DB::table('cities')->where('id', '>=', 31329)->increment('state_id');

Basically just found the Abdul Hakim record and noticed it was at id number 31329 in the database. I figured everything after that was what needed to be updated based on your post, so I just tell it to look at the table and increment state_id for anything after that id number.

Just thought I'd share in case anyone wants to update using this method. Worked for me.

hasnhasan commented 4 years ago

@omusovski Can you send the final file?

olivermusovski commented 4 years ago

CitiesTableSeeder.php.zip

Here it is zipped. The only thing that is changed from the original is very last line.

ibjorn commented 4 years ago

Thanks for the tip, but there's still serious issues. Looking at South Africa for instance, it gives 14 provinces, while we only have 9. It also brings up the wrong cities. There are so many records, I don't even know where to start to troubleshoot! Pity, I just had my AJAX dropdowns playing nicely.

omusovski commented 4 years ago

Yeah I've also noticed some issues in other countries like the UK where things are not entirely accurate. But like you said it's just too many records to try and fix manually.

ibjorn commented 4 years ago

I just made new seeds using this tool: https://github.com/orangehill/iseed And this DB: https://github.com/dr5hn/countries-states-cities-database

Data looks ok. Once I've checked it out properly I'll upload to a repository.