What's wrong with mysql reset auto increment in codeigniter? |
Hi, I'm a newbie in codeigniter. So far, I've tried to reset auto increment field in mysql using codeigniter.
Code: // Location: rb_model.php Unfortunately, it give me an error: Code: Error Number: 1064 It's really strange, because the code was working in sql command line. Any suggestion?
ALTER TABLE rancangan_bulanan AUTO_INCREMENT = 1
Why an reset? Normaly you do a "truncate table" for an reset. but you have to think about dependences.
ALTER TABLE tablename AUTO_INCREMENT = 1
There is a very easy way with phpmyadmin under the ( operations tab ), you can set, in the table options, autoincrement to the number you want. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-18-2017, 01:31 AM)InsiteFX Wrote: ALTER TABLE tablename AUTO_INCREMENT = 1 I think OP does want to do this, but also wants to renumber all of the old records, probably to remove missing ids that were deleted? If it were me, I'd probably just rename the table, recreate the original table, and then batch insert everything. Maybe there is an easier way.
1. Select all records and store in array or object. Maybe also save them to a JSON file
2. Truncate the table -> This will reset auto increment 3. (Re)Insert the records from step 1 -> remove existing ID column 4. Your ID's have been rearranged |
Welcome Guest, Not a member yet? Register Sign In |