Reposting this as I think it needs to be a separate issue.

I would like a feature to reset the counter to zero without uninstalling and reinstalling the serial module.

I have a database that I need to replace with a new one but can't figure out how to reset the counter to zero.

I looked in the DB with phpMyAdmin but couldn't figure it out. I went into the field table entry and set one remaining record to "1" but then when I created a new record of that content type, serial field picked up where it left off (1342) from the old set of records. I had deleted them all previously with a Views Bulk Operations view.

How can I reset the counter?

Comments

texas-bronius’s picture

It appears that a table is generated for each node type and field. Mine is serial_readingevent_field_eventno. At a glance, it appears that the sid is the next one in line. Oddly, an entry appears to be made only when this module is invoked: It seems that serial id only increases if I don't set the title manually (wherein I have a token referring to this serial field, using the autotitle module).

Anyhow, I'd like to hear how to set or reset the Serial Token counter too. If I learn something, I'll post back here.

texas-bronius’s picture

I haven't tried this yet, but I suspect that if you truncate the table for a given serial field (which would also likely set each node's serial id field to empty and set it up to be a new serial id on next edit of this node! (I would think)) and reset its sid field autoincrement value to 0, that your next New Node would be sid 1, or your next edit and save of an existing node with the same serial id would be 1.

It's a theory, and I didn't review the code-- just what it looks like might happen based on the table data.

-Bronius

texas-bronius’s picture

A couple findings:
Deleting all records in the serial table for this field and resetting auto_increment did not affect existing nodes (which kept the original serial id field values but gave me serial id value of 1 on new node creation.

So, armed with this knowledge, I manually adjusted the sid in the table (with only the new node in it now) to the desired value considering all other nodes of this content type already in the system and ran
alter table serial_readingevent_field_eventno auto_increment = 1
to set the next sid to be created back to last sid + 1.

I don't know what will happen when I hit an sid == one of the already existing "incorrect" sid values in their serial id field. Maybe I'm in for a world of hurt. Good luck -- please report back if you learn a better way to reset or set or tamper with serial id.

ilw’s picture

Subscribe.

alex.skrypnyk’s picture

subscribe

Jonasvh’s picture

SOLUTION

I just remove the serial field in my contenttype -> save the contenttype -> added the serial field again -> save the contenttype -> just wait, so that the module can execute -> done

Increase the PHP Execution time

Add to the .htacces file :

php_value max_execution_time 200

200 is the time in seconds

check some example: www.geografica.be

emkamau’s picture

Title: How to reset the counter? » Can I use existing autoincrement numbers
Issue tags: +migrate

I'm migrating data from a MySQL database with an autoincrement field. Can I simply import the numbers already in the db into a Serial field in Drupal and have autoincrement start from the largest number?

emk

texas-bronius’s picture

Title: Can I use existing autoincrement numbers » How to reset the serial field (serial) counter?
Status: Active » Fixed

Please open a new issue instead of hijacking an existing, documented, and resolved one.

Status: Fixed » Closed (fixed)
Issue tags: -migrate

Automatically closed -- issue fixed for 2 weeks with no activity.