Rectangle 27 10

ALTER TABLE `sugestoes`
ADD CONSTRAINT `FK_idproduto_produtos_1` FOREIGN KEY (`idproduto`) REFERENCES `produtos` (`id`),
ADD CONSTRAINT `FK_sugestoes_produtos_2` FOREIGN KEY (`idsugestao1`) REFERENCES `produtos` (`id`),
ADD CONSTRAINT `FK_sugestoes_produtos_3` FOREIGN KEY (`idsugestao2`) REFERENCES `produtos` (`id`),
ADD CONSTRAINT `FK_sugestoes_produtos_4` FOREIGN KEY (`idsugestao3`) REFERENCES `produtos` (`id`),  
ADD CONSTRAINT `FK_sugestoes_produtos_5` FOREIGN KEY (`idsugestao4`) REFERENCES `produtos` (`id`)

You can not specify

ON DELETE SET NULL

You have defined a SET NULL condition though some of the columns are defined as NOT NULL

You can see exact error when you run

SHOW ENGINE INNODB STATUS;

Longer works does not solve my problem, I need ON DELETE SET NULL and SET OnUpdate Cascade, when I try to make these changes, gives the same error message.

I need when the user DELETE some produto.idproduto the corresponding sugestao.idsugestao be null or empty, how can I set it?

Thanks, you helped a lot.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

foreign keys - MySQL Error : #1005 - Can't create table (errno: 150) W...

mysql foreign-keys mysql-error-1005
Rectangle 27 54

MySQLs generic errno 150 message means that a foreign key constraint was not correctly formed. As you probably already know if you are reading this page, the generic errno: 150 error message is really unhelpful. However:

SHOW ENGINE INNODB STATUS;
LATEST FOREIGN KEY ERROR
CREATE TABLE t1
(id INTEGER);

CREATE TABLE t2
(t1_id INTEGER,
 CONSTRAINT FOREIGN KEY (t1_id) REFERENCES t1 (id));

fails with the error Can't create table 'test.t2' (errno: 150). That doesnt tell anyone anything useful other than that its a foreign key problem. But run SHOW ENGINE INNODB STATUS; and it will say:

------------------------
LATEST FOREIGN KEY ERROR
------------------------
130811 23:36:38 Error in foreign key constraint of table test/t2:
FOREIGN KEY (t1_id) REFERENCES t1 (id)):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.

It says that the problem is it cant find an index. SHOW INDEX FROM t1 shows that there arent any indexes at all for table t1. Fix that by, say, defining a primary key on t1, and the foreign key constraint will be created successfully.

SHOW ENGINE INNODB STATUS helped me immediately identify a problem I'd been trying to diagnose for nearly an hour. Thanks.

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 10

What's the current state of your database when you run this script? Is it completely empty? Your SQL runs fine for me when creating a database from scratch, but errno 150 usually has to do with dropping & recreating tables that are part of a foreign key. I'm getting the feeling you're not working with a 100% fresh and new database.

If you're erroring out when "source"-ing your SQL file, you should be able to run the command "SHOW ENGINE INNODB STATUS" from the MySQL prompt immediately after the "source" command to see more detailed error info.

You may want to check out the manual entry too:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message. If MySQL reports an error number 1005 from a CREATE TABLE statement, and the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed.

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 122

There is probably another table with a foreign key referencing the primary key you are trying to change.

To find out which table caused the error you can run SHOW ENGINE INNODB STATUS and then look at the LATEST FOREIGN KEY ERROR section.

mysql - #1025 - Error on rename of './database/#sql-2e0f_1254ba7' to '...

mysql sql phpmyadmin innodb mysql-error-1025
Rectangle 27 10

Just clarifying what worked for me after much pain in linux (ubuntu based) on permission denied errors, and leveraging from Bert's answer above, I now use ...

$ pip install --user <package-name>

or if running pip on a requirements file ...

$ pip install --user -r requirements.txt

and these work reliably for every pip install including creating virtual environments.

python-virtualenv
virtualenvwrapper
sudo apt-get install

Then, inside virtual environments, use pip install without the --user flag AND without sudo. Much cleaner, safer, and easier overall.

python - pip install -r: OSError: [Errno 13] Permission denied - Stack...

python django pip
Rectangle 27 8

Just clarifying what worked for me after much pain in linux (ubuntu based) on permission denied errors, and leveraging from Bert's answer above, I now use ...

$ pip install --user <package-name>

or if running pip on a requirements file ...

$ pip install --user -r requirements.txt

and these work reliably for every pip install including creating virtual environments.

python-virtualenv
virtualenvwrapper
sudo apt-get install

Then, inside virtual environments, use pip install without the --user flag AND without sudo. Much cleaner, safer, and easier overall.

python - pip install -r: OSError: [Errno 13] Permission denied - Stack...

python django pip
Rectangle 27 3

As pointed by @andrewdotn the best way is to see the detailed error(SHOW ENGINE INNODB STATUS;) instead of just an error code.

One of the reasons could be that an index already exists with the same name, may be in another table. As a practice, I recommend prefixing table name before the index name to avoid such collisions. e.g. instead of idx_userId use idx_userActionMapping_userId.

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 27

As was said you need to remove the FKs before. On Mysql do it like this:

ALTER TABLE `table_name` DROP FOREIGN KEY `id_name_fk`;

ALTER TABLE `table_name` DROP INDEX `id_name_fk`;

mysql - #1025 - Error on rename of './database/#sql-2e0f_1254ba7' to '...

mysql sql phpmyadmin innodb mysql-error-1025
Rectangle 27 20

For those who are getting to this question via google... this error can also happen if you try to rename a field that is acting as a foreign key.

mysql - #1025 - Error on rename of './database/#sql-2e0f_1254ba7' to '...

mysql sql phpmyadmin innodb mysql-error-1025
Rectangle 27 2

Helpful tip, use SHOW WARNINGS; after trying your CREATE query and you will receive the error as well as the more detailed warning:

---------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                                                                                 |
+---------+------+--------------------------------------------------------------------------                          --------------------------------------------------------------------------------------------                          ---------------+
| Warning |  150 | Create table 'fakeDatabase/exampleTable' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
|
| Error   | 1005 | Can't create table 'exampleTable' (errno:150)                                                                                                                                                                           |
+---------+------+--------------------------------------------------------------------------                          --------------------------------------------------------------------------------------------                          ---------------+

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 13

To bypass this in PHPMyAdmin or with MySQL, first remove the foreign key constraint before renaming the attribute.

(For PHPMyAdmin users: To remove FK constrains in PHPMyAdmin, select the attribute then click "relation view" next to "print view" in the toolbar below the table structure)

mysql - #1025 - Error on rename of './database/#sql-2e0f_1254ba7' to '...

mysql sql phpmyadmin innodb mysql-error-1025
Rectangle 27 3

# grep python /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

This helped me SO much by putting me on the right track. Thanks! SELinux on CentOS 7 was blocking a Python call urllib/urllib2/requests from a .py file, but not from the Python command line and the error messages were not helpful. It was driving me crazy.

python - What causes "urlopen error [Errno 13] Permission denied" erro...

python beautifulsoup
Rectangle 27 4

Removing the mongodb.lock file was not the issue in my case. I did so and got an error about the port being in use: [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017. I found another solution here: unable to start mongodb local server with instructions to kill the process:

Find out from netstat which process is running mongodb port (27017)

sudo netstat -tulpn | grep :27017

sudo kill 1412 (replace 1412 with your process ID found in step 1)

And I was able to successfully start mongodb again. I believe mine was still running from an improper shut down.

mongodb - Unable to create/open lock file: /data/mongod.lock errno:13 ...

mongodb
Rectangle 27 1

This is usually happening when you try to source file into existing database. Drop all the tables first (or the DB itself). And then source file with SET foreign_key_checks = 0; at the beginning and SET foreign_key_checks = 1; at the end.

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 1

Problem: errno 150 on table X when trying to do Forward Engineering on a DB diagram, 20 out of 21 succeeded, 1 failed. If FKs on table X were deleted, the error moved to a different table that wasn't failing before.

Changed all tables engine to myISAM and it worked just fine.

MySQL Creating tables with Foreign Keys giving errno: 150 - Stack Over...

mysql foreign-keys errno
Rectangle 27 2

On a Fedora 18 with Mongo 2.2.4 instance I was able to get around a similar error by disabling SELinux by calling setenforce 0 as root.

BTW, this was a corporate environment, not an Amazon EC2 instance, but the symptoms were similar.

mongodb - Unable to create/open lock file: /data/mongod.lock errno:13 ...

mongodb
Rectangle 27 3

If you are trying to delete a column which is a FOREIGN KEY, you must find the correct name which is not the column name. Eg: If I am trying to delete the server field in the Alarms table which is a foreign key to the servers table.

SHOW CREATE TABLE alarm;
CONSTRAINT `server_id_refs_id_34554433` FORIEGN KEY (`server_id`) REFERENCES `server` (`id`)
ALTER TABLE `alarm` DROP FOREIGN KEY `server_id_refs_id_34554433`;
ALTER TABLE `alarm` DROP `server_id`

This will delete the foreign key server from the Alarms table.

mysql - #1025 - Error on rename of './database/#sql-2e0f_1254ba7' to '...

mysql sql phpmyadmin innodb mysql-error-1025
Rectangle 27 4

You've got author as part of your primary key, which means it's not nullable, but you've got ON DELETE SET NULL on the foreign key constraint on that field. These two conditions are incompatible.

To fix it, remove author from your PRIMARY KEY declaration; your id_newsletter field is already an auto_increment so should be unique unless your application sets it specifically (in which case you shouldn't use auto_increment).

It's a good idea to verify that the referenced field is indexed and has a compatible data type too; I can't see that from the provided information, but it's a good thing to add to your "errno 150 checklist" :)

If this answers your question, don't forget to mark it as correct!

I changed it but still don't work :/ I posted all the database up here!

Does the t_administrators table exist? it's not in this output.

mysql - ERROR: Error 1005: Can't create table (errno: 150) - Stack Ove...

mysql foreign-key-relationship mysql-workbench workbench
Rectangle 27 1

Using requests and providing a User-Agent header works for me:

from bs4 import BeautifulSoup
import requests

headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36'}
response = requests.get("https://librivox.org/selections-from-battle-pieces-and-aspects-of-the-war-by-herman-melville/", headers=headers)

soup = BeautifulSoup(response.content)
print soup.title.text  # "prints LibriVox"

thanks but that just gave me a different version of the Error 13

python - What causes "urlopen error [Errno 13] Permission denied" erro...

python beautifulsoup
Rectangle 27 1

Most likely, you don't have the permissions to write a file in that particular folder. Check if you have permissions to write in that particular folder. Also, defining an absolute path for the file might help.

python - xlwt error message IOError: [Errno 13] Permission denied: 'py...

python python-2.7 xlwt