0

I'm creating a Web api project on my Visual Studio Professional 2013. I would like to use EntityFramework to get data from a MySql Database. To do so, I followed the following steps:

  • Installed the .NET Connector for MySQL.
  • Created a Web Api project.
  • Installed Entity Framework via Nuget
  • Installed the Mysql Data provider via Nuget

In order to use Entity Framework, I wanted to add an ADO.NET Entity Data Model. The system found the connector and I'm able to create a connexion with my MySQL Database. The trageted database is also found and I'm about to add the databases' objects that I need in my ADO.NET Data Model. Here comes the error. When I'm trying to add a table which contains by default null value in some columns, the table is not added and errors are displayed saying the following: ERROR 13101: the component key 'name of the column' of the type 'name of the table' is not valid. Any component of the key can accept null value.

Here is the script that I use to create the table:

    CREATE TABLE `ps_address` (
  `id_address` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `id_country` int(10) unsigned NOT NULL,
  `id_state` int(10) unsigned DEFAULT NULL,
  `id_customer` int(10) unsigned NOT NULL DEFAULT '0',
  `id_manufacturer` int(10) unsigned NOT NULL DEFAULT '0',
  `id_supplier` int(10) unsigned NOT NULL DEFAULT '0',
  `id_warehouse` int(10) unsigned NOT NULL DEFAULT '0',
  `alias` varchar(32) NOT NULL,
  `company` varchar(64) DEFAULT NULL,
  `lastname` varchar(32) NOT NULL,
  `firstname` varchar(32) NOT NULL,
  `address1` varchar(128) NOT NULL,
  `address2` varchar(128)  DEFAULT NULL,
  `postcode` varchar(12)  DEFAULT NULL,
  `city` varchar(64) NOT NULL,
  `other` text,
  `phone` varchar(32)  DEFAULT NULL,
  `phone_mobile` varchar(32)  DEFAULT NULL,
  `vat_number` varchar(32) DEFAULT NULL,
  `dni` varchar(16) DEFAULT NULL,
  `date_add` datetime NOT NULL,
  `date_upd` datetime NOT NULL,
  `active` tinyint(1) unsigned NOT NULL DEFAULT '1',
  `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_address`),
  KEY `address_customer` (`id_customer`),
  KEY `id_country` (`id_country`),
  KEY `id_state` (`id_state`),
  KEY `id_manufacturer` (`id_manufacturer`),
  KEY `id_supplier` (`id_supplier`),
  KEY `id_warehouse` (`id_warehouse`)
    ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;

Is this a recurrent problem ? Maybe somebody has faced that issue before ?

Thanks in advance.

Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63
  • Are parts of your key nullable on said table? http://stackoverflow.com/questions/10888087/entity-framework-field-of-composite-key-cannot-be-nullable – Steve Greene Jun 12 '15 at 16:23
  • what do you mean ? Some columns are nullable and this is the origin of the problem... – Hubert Solecki Jun 12 '15 at 16:39
  • What he is saying is that you can't have a composite key that can potentially contain NULL values. Specify a PK for the table that cannot have NULL values. – 9ee1 Jun 14 '15 at 21:05

0 Answers0