Entity Framework error with MySql Provider

317 views Asked by At

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.

0

There are 0 answers