Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
  1. #11
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    40
    Somehow I managed to drop all tables and then recreate them. It worked and I got all tables. Now the problem is that I don't have any users and cant log in. I don't know if I should go on and see how to sign up a user or go back in the movies.

  2. #12
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    40
    Quote Originally Posted by mikael1000 View Post
    Somehow I managed to drop all tables and then recreate them. It worked and I got all tables. Now the problem is that I don't have any users and cant log in. I don't know if I should go on and see how to sign up a user or go back in the movies.
    Ok, so here I am answering my own question and talking to myself.

    What I did was to try to roll back, but that messed up the database completely. Thats when I dropped all tables. Then I ran The Powershell code and it created everything for me (_001, _002, _003). But I did not have any user and was kind of locked out. I decided to go into the code (after all I'm actually supposed to learn this I guess... hehe!) and mess with the code and I fixed it. Now I'm back on track.

    I really really like this tutorial.

  3. #13
    Join Date
    Jan 2013
    Posts
    14
    Still having issues migrating to _002. I rolled back all migrations when I noticed I had typed "user", and not "users" ("users", "id) for the foreign key line in the Create.Table("posts"). This did not help. _001 migrates fine. _002 dies after creating posts table...

    Code:
    using System.Data;
    using FluentMigrator;
    
    namespace SimpleBlog.Migrations
    {
        [Migration(2)]
        public class _002_PostsAndTags : Migration
        {
            public override void Up()
            {
                Create.Table("posts")
                    .WithColumn("id").AsInt32().PrimaryKey().Identity()
                    .WithColumn("user_id").AsInt32().ForeignKey("users", "id")
                    .WithColumn("title").AsString(128)
                    .WithColumn("slug").AsString(128)
                    .WithColumn("created_at").AsDateTime()
                    .WithColumn("updated_at").AsDateTime().Nullable()
                    .WithColumn("deleted_at").AsDateTime().Nullable();
    
                Create.Table("tags")
                    .WithColumn("id").AsInt32().PrimaryKey().Identity()
                    .WithColumn("slug").AsString(128)
                    .WithColumn("name").AsString(128);
    
                Create.Table("post_tags")
                    .WithColumn("tag_id").AsInt32().ForeignKey("tags", "id").OnDelete(Rule.Cascade)
                    .WithColumn("post_id").AsInt32().ForeignKey("posts", "id").OnDelete(Rule.Cascade);
            }
    
            public override void Down()
            {
                Delete.Table("post_tags");
                Delete.Table("posts");
                Delete.Table("tags");
            }
        }
    }
    Click image for larger version. 

Name:	Fluent_002.PNG 
Views:	173 
Size:	153.4 KB 
ID:	73915

  4. #14
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    Quote Originally Posted by sjurick View Post
    Still having issues migrating to _002. I rolled back all migrations when I noticed I had typed "user", and not "users" ("users", "id) for the foreign key line in the Create.Table("posts"). This did not help. _001 migrates fine. _002 dies after creating posts table...

    Code:
    using System.Data;
    using FluentMigrator;
    
    namespace SimpleBlog.Migrations
    {
        [Migration(2)]
        public class _002_PostsAndTags : Migration
        {
            public override void Up()
            {
                Create.Table("posts")
                    .WithColumn("id").AsInt32().PrimaryKey().Identity()
                    .WithColumn("user_id").AsInt32().ForeignKey("users", "id")
                    .WithColumn("title").AsString(128)
                    .WithColumn("slug").AsString(128)
                    .WithColumn("created_at").AsDateTime()
                    .WithColumn("updated_at").AsDateTime().Nullable()
                    .WithColumn("deleted_at").AsDateTime().Nullable();
    
                Create.Table("tags")
                    .WithColumn("id").AsInt32().PrimaryKey().Identity()
                    .WithColumn("slug").AsString(128)
                    .WithColumn("name").AsString(128);
    
                Create.Table("post_tags")
                    .WithColumn("tag_id").AsInt32().ForeignKey("tags", "id").OnDelete(Rule.Cascade)
                    .WithColumn("post_id").AsInt32().ForeignKey("posts", "id").OnDelete(Rule.Cascade);
            }
    
            public override void Down()
            {
                Delete.Table("post_tags");
                Delete.Table("posts");
                Delete.Table("tags");
            }
        }
    }
    Click image for larger version. 

Name:	Fluent_002.PNG 
Views:	173 
Size:	153.4 KB 
ID:	73915
    Did you rebuild the project before running the migration? According to the output, it's still trying to make an FK on the "user" table.
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •