Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-01-2007, 9:35 PM   #1
JMosey@gmail.com
 
JMosey@gmail.com's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

I have a table, this table has an autonumber as a primary key.

I export the table in phpMyAdmin.

Cool so far.

I create a new DB, I import the backup of the DB in that new DB and it
throws an error that the table with the automnumber already has a value
of 1 (it isn't incrementing the new table).

Ok, go back and hack through, remove the autonumber. Now export and it
imports fine.

Except how do I get the autonumber back? There are hundreds of rows of
data and I want that autonumber but when I try and add it it says there
is already an ID field with a "1" (same as before, not saying "find the
highest and add one more" just saying "start at 1, oops there is one,
then die"

Anyone know a way around this? I want to add my autonumber to my table
with the data that is already there.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Advertisements
Old 07-01-2007, 9:35 PM   #2
Rik
 
Rik's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

JMosey@gmail.com wrote:
> I have a table, this table has an autonumber as a primary key.
>
> I export the table in phpMyAdmin.
>
> Cool so far.
>
> I create a new DB, I import the backup of the DB in that new DB and it
> throws an error that the table with the automnumber already has a
> value of 1 (it isn't incrementing the new table).
>
> Ok, go back and hack through, remove the autonumber. Now export and it
> imports fine.
>
> Except how do I get the autonumber back? There are hundreds of rows of
> data and I want that autonumber but when I try and add it it says
> there is already an ID field with a "1" (same as before, not saying
> "find the highest and add one more" just saying "start at 1, oops
> there is one, then die"
>
> Anyone know a way around this? I want to add my autonumber to my table
> with the data that is already there.


Before (multi-)posting, try to read some of the answers already given in
different groups.

Export options:
- structure
- Add AUTO_INCREMENT value
- data
- Complete inserts

Should take car of the problem if you start with a clean table.

If for some reason, you can't gat this to work (and you should), you could
manually:
ALTER TABLE tbl AUTO_INCREMENT = next_integer_you_want;

Grtz,
--
Rik Wasmus


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #3
JMosey@gmail.com
 
JMosey@gmail.com's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

"If for some reason, you can't gat this to work (and you should), you
could
manually:
ALTER TABLE tbl AUTO_INCREMENT = next_integer_you_want; "

I did this and while the SQL didn't throw an error, none of the fields
are showing a autonumber in the structure table of phpMyAdmin

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #4
Peter H. Coffin
 
Peter H. Coffin's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

On 22 May 2006 10:42:53 -0700, JMosey@gmail.com wrote:
> "If for some reason, you can't gat this to work (and you should), you
> could
> manually:
> ALTER TABLE tbl AUTO_INCREMENT = next_integer_you_want; "
>
> I did this and while the SQL didn't throw an error, none of the fields
> are showing a autonumber in the structure table of phpMyAdmin


That will reset the integer on a table with a preexisting autoincrement.
If your table has no autoincrement fields right now, setting that does
not magically make a random field autoincrement. You still must specify
an autoincrement option on one of the fields. The complete specification
would be more along the lines of

ALTER TABLE `tbl` MODIFY `fld` INT UNSIGNED NOT NULL AUTO_INCREMENT,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`fld`)
AUTO_INCREMENT = value;

(Autoincrement fields must be part of the primary key, so we need
to include that field in the key. You *may* make the autoincrement
field part of a compound key, but that makes importing data somewhat
complicated. One often ends up dumping the relevant tables, merging the
outputs into a single (correct) load script, and then running the merged
script through the mysql client to create a whole NEW table. Personally,
I stick with just the single autoincrement field as primary key on
almost every table I build, and then manage relationships with user
indexes.)

--
I didn't need to sabotage anything. Not being around to say "No that
won't work" or "you can't do it that way" is more than enough damage.
(Ego problem? It's not a problem.)
-- Graham Reed, on job endings
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #5
Rik
 
Rik's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

JMosey@gmail.com wrote:
> "If for some reason, you can't gat this to work (and you should), you
> could
> manually:
> ALTER TABLE tbl AUTO_INCREMENT = next_integer_you_want; "
>
> I did this and while the SQL didn't throw an error, none of the fields
> are showing a autonumber in the structure table of phpMyAdmin


No, it won't magically all already existing fields to an autonumber field,
it will just set the next autonumber field. If already existing fields do
not have a number, it can't be easily set.

Have you tried the first option, while exporting selecting "add
autoincrement value" in structure, and COMPLETE inserts in data? That should
work, I use in all the time.

If this doesn't work, please post a complete list of settings you choose
while exporting in phpmyadmin

Grtz,
--
Rik Wasmus


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Old 07-01-2007, 9:35 PM   #6
Axel Schwenke
 
Axel Schwenke's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default autonumber troubles

JMosey@gmail.com wrote:

> I have a table, this table has an autonumber as a primary key.
> I export the table in phpMyAdmin.
> Cool so far.


No. phpMyAdmin is kind of "last resort" tool. If you have the
possibility, I recommend using the MySQL command line utilities.
In your case: mysqldump. Anyway, this time it's not phpMyAdmins fault.

> I create a new DB, I import the backup of the DB in that new DB and it
> throws an error that the table with the automnumber already has a value
> of 1 (it isn't incrementing the new table).
>
> Ok, go back and hack through, remove the autonumber. Now export and it
> imports fine.


I *guess* your original table has a row with value 0 in the
AUTO_INCREMENT column. At import time, this 0 is replaced with
the next AUTO_INCREMENT value - for an empty table that is 1.
Then the row with the "real" 1 gives you the duplicate key error.

How to fix:

Make sure you don't have the value 0 in an AUTO_INCREMENT column.


XL
--
Axel Schwenke, Senior Software Developer, MySQL AB

Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/
MySQL User Forums: http://forums.mysql.com/
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Featured Websites
Free Space
Free Space
Free Space Free Space
Closed Thread
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubles with a class function. NeoPhreak PHP 0 07-01-2007 5:25 PM
Palette troubles. Steven Software Programming 3 06-12-2007 9:41 PM
Export MS Access tables with random autonumber fields to MySQL GGL Database 0 05-31-2007 8:39 PM
CD7 printing troubles Stefano C.A. Rossi Graphics in general 1 05-28-2007 7:46 PM


Featured Websites




All times are GMT +1. The time now is 12:06 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98