MySQL Workbench Edit Table Data is read only
Asked Answered
P

16

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.

Puzzler answered 30/5, 2012 at 11:6 Comment(3)
Nothing of the suggested question is working. I can't add a column then remove it. Moving to phpMyadmin is my choice now.Cachexia
The PK is required, here's a related FAQ -- dev.mysql.com/doc/workbench/en/…Seigneury
Possibly relevant MySQL Workbench bug for people who found this thread with a web search: views' result grids are not editable. Note that this bug only pertains to views which meet all the other constraints required to be "updatable" and can be modified with straight SQL queries.Ballarat
G
102

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.

Gillenwater answered 1/7, 2012 at 16:21 Comment(5)
Actually my problem is itself I do not want to have primary key in my table. Please refer to the other answer for this question.Puzzler
I don't think what you do is possible in MYSQL workbench since the program needs a primary key to pin point which row you want to edit.Gillenwater
Okie.Thank you Thomas. I have included primary key in my tables.Puzzler
I was using DBeaver and faced same problem. Disconnecting and connecting again solved it!Pincer
Disconnecting and connecting again solved it for me, too!Cheiro
P
48

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

Plafker answered 8/5, 2013 at 9:24 Comment(2)
I guess there are not solution for this.Uriel
That's the best answer here. If you can Alter the table, you can set the PK to allow editing!Palocz
C
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.

Cerography answered 23/8, 2012 at 14:42 Comment(0)
P
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
Perfectible answered 4/3, 2016 at 10:54 Comment(1)
More recent versions of MySQL Workbench (mine is 6.3) do not have an "Edit Table Data" option.Workshop
D
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.

Dorree answered 8/10, 2013 at 10:51 Comment(2)
where is this icon you speak of?Antemundane
answering myself: it's below and to the right of the results on workbench 6.3Antemundane
S
5

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;

Squally answered 30/8, 2018 at 18:38 Comment(0)
L
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)

Luker answered 13/11, 2015 at 13:42 Comment(0)
C
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 ! :)

Chandra answered 27/4, 2021 at 20:22 Comment(0)
B
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
Bialy answered 30/5, 2012 at 11:14 Comment(5)
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...Puzzler
@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?Bialy
Nope.. its not working.. Am getting concat(''.'') as another column in result set but still data is read only.. Now am upgrading WBPuzzler
@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.Bialy
It is the same case in 5.2.44. The database is a productive one and works fine in previous version of workbench.Hostile
L
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.

Levitan answered 20/5, 2014 at 14:14 Comment(0)
P
1

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.

Principate answered 4/8, 2023 at 7:31 Comment(0)
H
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".

Hostile answered 19/11, 2012 at 22:34 Comment(0)
B
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.

Bartlett answered 24/3, 2015 at 3:40 Comment(1)
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);Auditory
D
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.

Deliadelian answered 4/6, 2020 at 9:8 Comment(0)
J
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.

Joan answered 17/9, 2020 at 23:15 Comment(0)
A
-1

enter image description here

Uncheck the marked check, it will enable the grid edit

Armes answered 20/4, 2020 at 19:38 Comment(1)
Uncheck the marked check, it will enable the grid edit: Not working - Workbench 8.0Plauen

© 2022 - 2024 — McMap. All rights reserved.