输入多个外键时,我无法在SQL中创建表

时间:2018-04-04 07:25:52

标签: mysql sql

下面是我的SQL文件,当我尝试在sql中插入多个外键时,不会创建该表。错误是“”异常形成外键约束

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    var ignore = base.OnCreateView(inflater, container, savedInstanceState);

    var view = this.BindingInflate(FragmentId, null);

    Toolbar = view.FindViewById<Toolbar>(Resource.Id.toolbar);
    if (Toolbar != null)
    {
        var mainActivity = Activity as MainActivity;
        if (mainActivity == null) return view;

        mainActivity.SetSupportActionBar(Toolbar);
        mainActivity.SupportActionBar?.SetDisplayHomeAsUpEnabled(true);
        DrawerToggle = new MvxActionBarDrawerToggle(
            Activity,                               // host Activity
            mainActivity.DrawerLayout,  // DrawerLayout object
            Toolbar,                               // nav drawer icon to replace 'Up' caret
            Resource.String.drawer_open,            // "open drawer" description
            Resource.String.drawer_close            // "close drawer" description
        );

        if (ShowHamburgerMenu)
        {
            DrawerToggle.DrawerOpened += (sender, e) =>
            {
                mainActivity?.HideSoftKeyboard();
            };
            mainActivity.DrawerLayout.AddDrawerListener(DrawerToggle);
        }

        DrawerToggle.DrawerIndicatorEnabled = ShowHamburgerMenu;
        Toolbar.NavigationClick += Toolbar_NavigationClick;
    }
    return view;
}

来自(现已删除)的评论:

 CREATE TABLE company_domaindetails (
    domain_id int NOT NULL,
    domain_name VARCHAR(200) NOT NULL,
    domain_provider VARCHAR(200) NOT NULL,
    domain_accoemail VARCHAR(200) NOT NULL,
    domain_allopassword VARCHAR(200) NOT NULL,
    domain_dns VARCHAR(200) NOT NULL,
    domain_timeframe VARCHAR(200) NOT NULL,
    domain_daysremaining VARCHAR(200) NOT NULL,
    company_id int,
    company_name varchar(200),
    PRIMARY KEY (domain_id),
    FOREIGN KEY (company_id) REFERENCES company_details(company_id),
    FOREIGN KEY (company_name) REFERENCES company_details(company_id)    
);

1 个答案:

答案 0 :(得分:1)

您必须指定一次外键创建并添加两列。 检查以下

CREATE TABLE company_details ( company_id int NOT NULL, company_name VARCHAR(200) NOT NULL,
 company_address VARCHAR(200), company_contactperson VARCHAR(200),
  company_contactno VARCHAR(200), company_email VARCHAR(200),
 PRIMARY KEY (company_id,company_name) )

根据您提供的DDL,并将表名称指定为company_domaindetails

CREATE TABLE company_domaindetails (
    domain_id int NOT NULL,
    domain_name VARCHAR(200) NOT NULL,
    domain_provider VARCHAR(200) NOT NULL,
    domain_accoemail VARCHAR(200) NOT NULL,
    domain_allopassword VARCHAR(200) NOT NULL,
    domain_dns VARCHAR(200) NOT NULL,
    domain_timeframe VARCHAR(200) NOT NULL,
    domain_daysremaining VARCHAR(200) NOT NULL,
    company_id int not null,
    company_name varchar(200),
    PRIMARY KEY (domain_id,company_name),
    FOREIGN KEY (company_id,company_name) REFERENCES company_details(company_id,company_name)
    )