0

I have one table in my database in Cpanel server in which there are 17 columns currently,out of them,one is auto incremented field(which is a primary key). currently in that table I have 600k rows. I want to add a new column to table,but I'm getting the following error

1034-137 while fixing the table

Alter command I am using for adding the column

ALter table 'tablename' add 'columnname' Varchar(200) NOT NULL

Please help me what should i do to add the columns to the existing table

James Z
  • 12,209
  • 10
  • 24
  • 44

2 Answers2

1

Because the new column does not allow NULL values, you will need to specify a default value for the column. All the existing rows in the table will be populated with the default value for the new column when you alter the table.

For example, to set the default value to empty string, you can use this statement.

alter table 'tablename' add 'columnname' Varchar(200) NOT NULL DEFAULT ''

Here is some documentation on using DEFAULT.

You can also drop the DEFAULT constraint after altering the table, so that future inserts into the table will fail if there is an attempt to insert a NULL value into that column,

Adam Porad
  • 14,193
  • 3
  • 31
  • 56
  • I am getting the same error when i m using the command given by you.Please help sir. – user3826682 Jul 10 '14 at 18:49
  • What kind of database are you using (e.g. SQL Server, MySQL, Oracle, etc.)? – Adam Porad Jul 10 '14 at 18:53
  • Perhaps, try looking at the answers to this other question. [Adding a new SQL column with a default value](http://stackoverflow.com/questions/3569347/adding-a-new-sql-column-with-a-default-value) – Adam Porad Jul 10 '14 at 18:58
  • Its the same command that you have given me,which are not working.I m getting this unknown error,i dnt know why.Does it depend on previous columns configuration also??? – user3826682 Jul 10 '14 at 19:03
0

After researching the error it seems that the indexing on your table may be having issues. Which tables are indexed other than your primary key?

In phpmyadmin select your table, then on the toolbar open Operations.

Under "Table maintenance" on the right hand side click the check table link to find out if there are any errors.

You may need to do some reindexing to correct the error.

EternalHour
  • 8,308
  • 6
  • 38
  • 57