title: EF Core - may cause cycles or multiple cascade paths
body: <p>I've set up what I thought was a pretty simple database.. However I am getting the following error.</p>
  
  <blockquote>
    <p>Introducing FOREIGN KEY constraint 'FK_User_Suburb_SuburbId' on table 'User' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
    Could not create constraint or index. See previous errors.</p>
  </blockquote>
  
  <p>Here is my CATALOGCOntext:</p>
  
  <pre><code>using JobsLedger.CATALOG.Entities;
  using Microsoft.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore.Metadata.Internal;
  
  namespace JobsLedger.CATALOG
  {
      public class CATALOGContext : DbContext
      {
          public DbSet&lt;Tenant&gt; Tenants { get; set; }
          public DbSet&lt;User&gt; Users { get; set; }
          public DbSet&lt;Role&gt; Roles { get; set; }
          public DbSet&lt;State&gt; States { get; set; }
          public DbSet&lt;Suburb&gt; Suburbs { get; set; }
          public DbSet&lt;CATALOGCounter&gt; Counters { get; set; }
  
  
          public CATALOGContext(DbContextOptions options) : base(options) { }
  
  
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              foreach (var entity in modelBuilder.Model.GetEntityTypes())
              {
                  entity.Relational().TableName = entity.DisplayName();
              }
  
              // User
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.UserName).IsRequired().HasMaxLength(50);
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.UserFirstName).IsRequired().HasMaxLength(100);
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.UserLastName).IsRequired().HasMaxLength(100);
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.Email).IsRequired().HasMaxLength(200);
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.HashedPassword).IsRequired().HasMaxLength(200);
              modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.Salt).IsRequired().HasMaxLength(200);
  
              modelBuilder.Entity&lt;User&gt;()
                  .HasOne&lt;Suburb&gt;(s =&gt; s.Suburb)
                  .WithMany(u =&gt; u.Users)
                  .HasForeignKey(u =&gt; u.SuburbId)
                  .IsRequired(false);
  
              // Role
              modelBuilder.Entity&lt;Role&gt;().Property(r =&gt; r.Name).IsRequired().HasMaxLength(50);
  
              modelBuilder.Entity&lt;Role&gt;()
                  .HasOne&lt;User&gt;(u =&gt; u.User)
                  .WithOne(r =&gt; r.Role)
                  .HasForeignKey&lt;User&gt;(u =&gt; u.RoleId);
  
              // TenantAccount
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.TenantNo).HasMaxLength(20);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.Company).HasMaxLength(100).IsRequired();
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.ContactLastName).HasDefaultValue(false).IsRequired();
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.Email).HasMaxLength(500).IsRequired();
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.MobilePhone).HasMaxLength(20).IsRequired();
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.OfficePhone).HasMaxLength(20);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.CompanyEmail).HasMaxLength(500);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.Address1).HasMaxLength(500);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.Address2).HasMaxLength(500);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.ABN).HasMaxLength(14);
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.Database).HasMaxLength(100).IsRequired();
              modelBuilder.Entity&lt;Tenant&gt;().Property(t =&gt; t.IsLocked).HasDefaultValue(false);
  
              modelBuilder.Entity&lt;Tenant&gt;()
                  .HasOne&lt;User&gt;(s =&gt; s.User)
                  .WithMany(ta =&gt; ta.Tenants)
                  .HasForeignKey(u =&gt; u.UserId);
  
              modelBuilder.Entity&lt;Tenant&gt;()
                  .HasOne(s =&gt; s.Suburb)
                  .WithMany(ta =&gt; ta.Tenants)
                  .HasForeignKey(ta =&gt; ta.SuburbId);
  
              // State
              modelBuilder.Entity&lt;State&gt;().Property(s =&gt; s.StateShortName).HasMaxLength(3).IsRequired();
              modelBuilder.Entity&lt;State&gt;().Property(s =&gt; s.StateName).HasMaxLength(30).IsRequired();
  
              // Suburb
              modelBuilder.Entity&lt;Suburb&gt;().Property(s =&gt; s.SuburbName).HasMaxLength(3).IsRequired();
              modelBuilder.Entity&lt;Suburb&gt;().Property(s =&gt; s.PostCode).HasMaxLength(30).IsRequired();
  
              modelBuilder.Entity&lt;Suburb&gt;()
                  .HasOne&lt;State&gt;(s =&gt; s.State)
                  .WithMany(su =&gt; su.Suburbs)
                  .HasForeignKey(st =&gt; st.StateId);
          }
      }
  }
  </code></pre>
  
  <p>Here is my user:</p>
  
  <pre><code>...
          public int? SuburbId { get; set; }
          public Suburb Suburb { get; set; }
  
          public int RoleId { get; set; }
          public Role Role { get; set; }
  
          public virtual ICollection&lt;Tenant&gt; Tenants { get; set; }
  </code></pre>
  
  <p>Here is my Suburb which was also mentioned..</p>
  
  <p>Wondering if someone might highlight why the migrations work but when I try and spin up a database it it errors with above error..</p>
  
  <p>Simon</p>