Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Column length change using Entity Framework Code First

Column length change using Entity Framework Code First

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpdatabasecollaborationtoolsquestion
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simpledeveloper
    wrote on last edited by
    #1

    Hi I am trying to alter a column to fit max length - I changed the entity property and ran Add migration - it did well in the first then in committing it on Git or over written by the remote branch or something its last when I was merging it in master branch then onwards it started giving me issues - my property that I changed is as follows:

    [StringLength(7999)]
    public string EventComment { get; set; }

    When I am creating - its creating the migration script as below:

    public partial class AlterColumnLemgthEventComment : DbMigration
    {
    public override void Up()
    {
    }

            public override void Down()
            {
            }
    }
    

    I tried in the following ways to workaround for it Even though I made it EventComment 1000 in Database then deleted my migration file - then ran the add migration now the file is created in the above way - not able to do anything - now its not let me login to the application as the database is failing - any help please - later its failing if I make the EventComment length max in Database and ran the application - still its failing validation errors. Any help please - just get away from validating any more from Code First, its painful to care things this much. Any help please. When I make the Database field as Max and Entity property also as 7999 - still it is giving me the following exception in the application - just not able to decide

    The field EventComment must be a string with a maximum length of 1000.

    I am getting the following error while trying to run the add migration

    The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration.
    If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration AlterColumnLemgthEventComment' again.

    Any help please?

    L Richard DeemingR 2 Replies Last reply
    0
    • S simpledeveloper

      Hi I am trying to alter a column to fit max length - I changed the entity property and ran Add migration - it did well in the first then in committing it on Git or over written by the remote branch or something its last when I was merging it in master branch then onwards it started giving me issues - my property that I changed is as follows:

      [StringLength(7999)]
      public string EventComment { get; set; }

      When I am creating - its creating the migration script as below:

      public partial class AlterColumnLemgthEventComment : DbMigration
      {
      public override void Up()
      {
      }

              public override void Down()
              {
              }
      }
      

      I tried in the following ways to workaround for it Even though I made it EventComment 1000 in Database then deleted my migration file - then ran the add migration now the file is created in the above way - not able to do anything - now its not let me login to the application as the database is failing - any help please - later its failing if I make the EventComment length max in Database and ran the application - still its failing validation errors. Any help please - just get away from validating any more from Code First, its painful to care things this much. Any help please. When I make the Database field as Max and Entity property also as 7999 - still it is giving me the following exception in the application - just not able to decide

      The field EventComment must be a string with a maximum length of 1000.

      I am getting the following error while trying to run the add migration

      The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration.
      If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration AlterColumnLemgthEventComment' again.

      Any help please?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Much ado about nothing. Check the length "before" saving instead of relying on "scaffolding".

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      S 1 Reply Last reply
      0
      • S simpledeveloper

        Hi I am trying to alter a column to fit max length - I changed the entity property and ran Add migration - it did well in the first then in committing it on Git or over written by the remote branch or something its last when I was merging it in master branch then onwards it started giving me issues - my property that I changed is as follows:

        [StringLength(7999)]
        public string EventComment { get; set; }

        When I am creating - its creating the migration script as below:

        public partial class AlterColumnLemgthEventComment : DbMigration
        {
        public override void Up()
        {
        }

                public override void Down()
                {
                }
        }
        

        I tried in the following ways to workaround for it Even though I made it EventComment 1000 in Database then deleted my migration file - then ran the add migration now the file is created in the above way - not able to do anything - now its not let me login to the application as the database is failing - any help please - later its failing if I make the EventComment length max in Database and ran the application - still its failing validation errors. Any help please - just get away from validating any more from Code First, its painful to care things this much. Any help please. When I make the Database field as Max and Entity property also as 7999 - still it is giving me the following exception in the application - just not able to decide

        The field EventComment must be a string with a maximum length of 1000.

        I am getting the following error while trying to run the add migration

        The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration.
        If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration AlterColumnLemgthEventComment' again.

        Any help please?

        Richard DeemingR Online
        Richard DeemingR Online
        Richard Deeming
        wrote on last edited by
        #3

        simpledeveloper wrote:

        in committing it on Git or over written by the remote branch

        If you've got multiple developers generating migrations at the same time, things can get very confused. Especially if you're all using the same development database instance. Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]

        simpledeveloper wrote:

        Even though I made it EventComment 1000 in Database then deleted my migration file - then ran the add migration

        As explained in the article above, Add-Migration doesn't look at the database; it looks at the model snapshot stored with the last migration. Manually changing the database won't cause EF to generate a migration to change it back.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        S 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          simpledeveloper wrote:

          in committing it on Git or over written by the remote branch

          If you've got multiple developers generating migrations at the same time, things can get very confused. Especially if you're all using the same development database instance. Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]

          simpledeveloper wrote:

          Even though I made it EventComment 1000 in Database then deleted my migration file - then ran the add migration

          As explained in the article above, Add-Migration doesn't look at the database; it looks at the model snapshot stored with the last migration. Manually changing the database won't cause EF to generate a migration to change it back.


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          S Offline
          S Offline
          simpledeveloper
          wrote on last edited by
          #4

          Can you please help me what can I do now - yes it seems that it is storing in snapshot - how can I clean it up - I am feeling very discomfort in changing things as it stored in snapshot and any mistake like the one above it happened because of merging - it made it very difficult - any help please. Can you please suggest me something please - thank you.

          Richard DeemingR 1 Reply Last reply
          0
          • L Lost User

            Much ado about nothing. Check the length "before" saving instead of relying on "scaffolding".

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

            S Offline
            S Offline
            simpledeveloper
            wrote on last edited by
            #5

            I have to be able to insert max size string rather 1000 length string

            1 Reply Last reply
            0
            • S simpledeveloper

              Can you please help me what can I do now - yes it seems that it is storing in snapshot - how can I clean it up - I am feeling very discomfort in changing things as it stored in snapshot and any mistake like the one above it happened because of merging - it made it very difficult - any help please. Can you please suggest me something please - thank you.

              Richard DeemingR Online
              Richard DeemingR Online
              Richard Deeming
              wrote on last edited by
              #6

              Resolving the merge conflict - Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              S 1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                Resolving the merge conflict - Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                S Offline
                S Offline
                simpledeveloper
                wrote on last edited by
                #7

                Hi Richard - how can I freshly generate add migration because its not creating me the same again. So I want to generate the migration file again how can I? The file is gone I am not looking for it - merging links help me but for future to be careful. Now I want to regenerate the migration files with the code what can I do? Its not allowing me. Please need help.

                Richard DeemingR F 2 Replies Last reply
                0
                • S simpledeveloper

                  Hi Richard - how can I freshly generate add migration because its not creating me the same again. So I want to generate the migration file again how can I? The file is gone I am not looking for it - merging links help me but for future to be careful. Now I want to regenerate the migration files with the code what can I do? Its not allowing me. Please need help.

                  Richard DeemingR Online
                  Richard DeemingR Online
                  Richard Deeming
                  wrote on last edited by
                  #8

                  Read the document I linked to - it explains what you need to do. Resolving the merge conflict - Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                  S 1 Reply Last reply
                  0
                  • Richard DeemingR Richard Deeming

                    Read the document I linked to - it explains what you need to do. Resolving the merge conflict - Code First Migrations in Team Environments - EF6 | Microsoft Docs[^]


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    S Offline
                    S Offline
                    simpledeveloper
                    wrote on last edited by
                    #9

                    Again thank you Richard my friend - thanks a lot :)

                    1 Reply Last reply
                    0
                    • S simpledeveloper

                      Hi Richard - how can I freshly generate add migration because its not creating me the same again. So I want to generate the migration file again how can I? The file is gone I am not looking for it - merging links help me but for future to be careful. Now I want to regenerate the migration files with the code what can I do? Its not allowing me. Please need help.

                      F Offline
                      F Offline
                      Fortnite Free V Bucks Generator 2020
                      wrote on last edited by
                      #10

                      great job man that really looks cool

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups