103

When trying Edit Table Data in MySQL Workbench 5.2.37, its in read only mode.

It is editable only if the table has a primary key.

Is there any fix to deal with table without primary key?

As one of the suggestion I tried upgrading WB 5.2.40. But still this issue exists.

starball
  • 20,030
  • 7
  • 43
  • 238
EscalinNancy
  • 1,252
  • 3
  • 10
  • 13
  • Nothing of the suggested question is working. I can't add a column then remove it. Moving to phpMyadmin is my choice now. – ophidion Aug 14 '13 at 19:30
  • The PK is required, here's a related FAQ -- http://dev.mysql.com/doc/workbench/en/workbench-faq.html#qandaitem-A-3-1 – Philip Olson Jan 02 '15 at 18:10
  • Possibly relevant MySQL Workbench bug for people who found this thread with a web search: [views' result grids are not editable](https://bugs.mysql.com/bug.php?id=83195). Note that this bug only pertains to _views_ which meet all the other constraints required to be "[updatable](https://dev.mysql.com/doc/refman/5.6/en/view-updatability.html)" and can be modified with straight SQL queries. – TheDudeAbides Dec 29 '17 at 05:02

16 Answers16

100

I'm assuming the table has a primary key. First try to run a unlock tables command to see if that fixes it.

If all else fails you can alter the table to create a new primary key column with auto-increment and that should hopefully fix it. Once you're done you should be able to remove the column without any issues.

As always you want to make a backup before altering tables around. :)

Note: MySQL workbench cannot work without a primary key if that's your issue. However if you have a many to many table you can set both columns as primary keys which will let you edit the data.

Thomas B
  • 1,184
  • 1
  • 9
  • 15
45

if the table does not have primary key or unique non-nullable defined, then MySql workbench could not able to edit the data.

Tarun Singhal
  • 977
  • 8
  • 11
17

If you set a default schema for your DB Connection then Select will run in readonly mode until you set explicitly your schema

USE mydb;
SELECT * FROM mytable

this will also run in edit mode:

SELECT * FROM mydb.mytable 

(MySql 5.2.42 / MacOsX)

I hope this helps.

HerrimanCoder
  • 6,835
  • 24
  • 78
  • 158
Manitoba
  • 201
  • 2
  • 3
10

This is the Known limitation in MySQLWorkbench (you can't edit table w/o PK):

To Edit the Table:

Method 1: (method not working in somecases)
right-click on a table within the Object Browser and choose the Edit Table Data option from there.

Method 2:
I would rather suggest you to add Primary Key Instead:

ALTER TABLE `your_table_name` ADD PRIMARY KEY (`column_name`);

and you might want to remove the existing rows first:

Truncate table your_table_name
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
  • 1
    More recent versions of MySQL Workbench (mine is 6.3) do not have an "Edit Table Data" option. – JonP Mar 24 '16 at 11:27
8

Hovering over the icon "read only" in mysql workbench shows a tooltip that explains why it cannot be edited. In my case it said, only tables with primary keys or unique non-nullable columns can be edited.

Tarun Garg
  • 153
  • 3
  • 12
4

I was getting the read-only problem even when I was selecting the primary key. I eventually figured out it was a casing problem. Apparently the PK column must be cased the same as defined in the table. using: workbench 6.3 on windows

Read-Only

SELECT leadid,firstname,lastname,datecreated FROM lead;

Allowed edit

SELECT LeadID,firstname,lastname,datecreated FROM lead;

Quad9x
  • 41
  • 2
3

In MySQL Workbench you need an INDEX to edit, no need it to be PK (although adding a PK is a solution as well).

You can make a regular INDEX or compound INDEX. That's all MySQL WB needs to fix the Read only thing (I have v. 6.2 with MariaDB v. 10.1.4):

Just right click table, select "Alter table..." then go to "Indexes" tab. In the left pane put a custom name for your index, and in the middle pane checkmark one (make sure the vale will be unique) or more fields (just make sure the combination is unique)

aesede
  • 5,541
  • 2
  • 35
  • 33
2

If your table is in read-only mode, checking first is the primary key. If the primary key is not defined, add as the following,

ALTER TABLE scema_here.table_name_here ADD PRIMARY KEY (your primary key here);

Cheers ! :)

janadari ekanayaka
  • 3,742
  • 2
  • 13
  • 17
1

According to this bug, the issue was fixed in Workbench 5.2.38 for some people and perhaps 5.2.39 for others—can you upgrade to the latest version (5.2.40)?

Alternatively, it is possible to workaround with:

SELECT *,'' FROM my_table
eggyal
  • 122,705
  • 18
  • 212
  • 237
  • Thank you for such a quick response.. Alternate SELECT is not working.. But I can upgrade.. Will upgrade and check it.. Thanks a lot eggyal... – EscalinNancy May 30 '12 at 11:20
  • @EscalinNancy: Another person in that bug report commented that an alternative workaround is to use a function e.g. `SELECT *, CONCAT('','') FROM my_table`. Perhaps that will work for you? – eggyal May 30 '12 at 11:21
  • Nope.. its not working.. Am getting concat(''.'') as another column in result set but still data is read only.. Now am upgrading WB – EscalinNancy May 30 '12 at 11:25
  • @EscalinNancy: I'm sorry to hear that :( It's possible someone else on here might have more of an idea what the problem is - but it's more likely they'll see this question if you unaccept my answer. – eggyal Jun 01 '12 at 08:13
  • It is the same case in 5.2.44. The database is a productive one and works fine in previous version of workbench. – Earth Engine Nov 19 '12 at 22:21
1

1.)You have to make the primary key unique, then you should be able to edit.

right click on you table in the "blue" schemas ->ALTER TABLE, look for your primert key (PK), then just check the check-box, UN, the AI should already be checked. After that just apply and you should be able to edit the table data.

2.)You also need to include the primery key I your select statement

Nr 1 is not really necessary, but a good practice.

Degar007
  • 107
  • 1
  • 5
0

Guided by Manitoba's post, I found another solution. As a summary, the solutions are:

  1. With a USE command

    USE mydb;
    SELECT * FROM mytable
    
  2. With an explicit schema prefix:

    SELECT * FROM mydb.mytable
    
  3. GUI

    On Object Browser "SCHEMAS" pane, all database icons are initially not highlighted if you have the same issue. So you can right click on the database icon you wanted to be the default, select "Set as default schema".

Earth Engine
  • 10,048
  • 5
  • 48
  • 78
0

If your query has any JOINs, Mysql Workbench will not allow you to alter the table, even if your results are all from a single table.

For example, the following query

SELECT u.* FROM users u JOIN passwords p ON u.id=p.user_id WHERE p.password IS NULL;

will not allow you to edit the results or add rows, even though the results are limited to one table. You must specifically do something like:

SELECT * FROM users WHERE id=1012;

and then you can edit the row and add rows to the table.

Keith Tyler
  • 719
  • 4
  • 18
  • I do not understand why the first query does not work, but at least the following query works.you could edit the following query works. `SELECT u.* FROM users u WHERE u.id IN (SELECT user_id FROM passwords WHERE p.password IS NULL);` – twk Feb 07 '20 at 04:01
0

MySQL will run in Read-Only mode when you fetch by joining two tables and columns from two tables are included in the result. Then you can't update the values directly.

0

Yes, I found MySQL also cannot edit result tables. Usually results tables joining other tables don't have primary keys. I heard other suggested put the result table in another table, but the better solution is to use Dbeaver which can edit result tables.

How
  • 26
  • 3
0

The fundamental issue is that mysql will not let you edit a table unless it has a primary key (if you've made it to this post then you likely know that by now).

So solution 1 is: If you have a Primary Key and have not declared it, declare it, click apply and edit the table

But the problem that I ran into was different and I wish this post had been there.

I had created a table to show the many-to-many relationship between two tables. The table consisted of two columns (Table 1 PK and Table 2 PK) but neither of these columns could be the primary key of this join table and I didn't want to create a 3rd column just for a PK.

The solution was to declare BOTH columns as PK! That way the table checks to make sure the combination of col 1 and col 2 are unique AND then I was able to edit the table.

The obvious bonus is that now mySQL will check that I don't enter a duplicate since the combination must always be unique.

starball
  • 20,030
  • 7
  • 43
  • 238
-1

enter image description here

Uncheck the marked check, it will enable the grid edit

devansdev
  • 75
  • 2
  • 9
  • 1
    Uncheck the marked check, it will enable the grid edit: Not working - Workbench 8.0 – JBC May 07 '21 at 19:34