Rename column with the entity framework

2

I'd like to know how I can solve the following problem. I have the class below:

namespace CustomizandoCodeFirstMigrations.Migrations
{
    using System;
    using System.Data.Entity.Migrations;

    public partial class AlteraTelefoneFixoRenomeiaCelular : DbMigration
    {
        public override void Up()
        {
            RenameColumn("dbo.Pessoas", "Celular", "TelefoneCelular");
            AlterColumn("dbo.Pessoas", "TelefoneFixo", c => c.String(nullable: false, unicode: false));
        }

        public override void Down()
        {
            RenameColumn("dbo.Pessoas", "TelefoneCelular", "Celular");
            AlterColumn("dbo.Pessoas", "TelefoneFixo", c => c.String());
        }
    }
}

And when I type in the package manager console the command update-database I receive in response:

  

Subquery returns more than 1 row

    
asked by anonymous 23.12.2015 / 14:38

1 answer

0

At your verbose command, we have:

set @columnType := (select 
                     case lower(IS_NULLABLE) 
                         when 'no' then         
                             CONCAT(column_type, ' not null ') 
                         when 'yes' then 
                             column_type 
                         end 
                     from information_schema.columns 
                     where table_name = 'Pessoas' 
                     and column_name = 'Celular'); 
 set @sqlstmt := (select concat('alter table Pessoas 
                                 change Celular TelefoneCelular ', @columnType)); 
 prepare stmt from @sqlstmt; 
 execute stmt; 
 deallocate prepare stmt;'

The @columnType command received two instances of Pessoa , so its error.

schema is a path, but I am in favor of a more lenient solution, which would just delete the Pessoa table from this other schema .

    
23.12.2015 / 19:18