我创建了几个表:
KEYNEEDS TABLE:
Public Sub CommandButton1_Click()
'Variables
Sheets("Today_Data").Select
Dim LastRow As Long, nRow As Long, eRow As Long, eRow2 As Long, eRow3 As Long
Set LastRow = SelectedSheets.Range("A" & Rows.Count).End(xlUp).Row
'''verify where is the last row updated today'
For nRow = 5 To LastRow Step 1
If Cells(nRow, 1).Value = Date Then
'''copy and paste only the cells that have been updated today
''Copy and paste columns 1-4 WITHOUT transposing
SelectedSheets.Range(SelectedSheets.Cells(nRow, 1), SelectedSheets.Cells(nRow, 2), SelectedSheets.Cells(nRow, 3), SelectedSheets.Cells(nRow, 4)).Select
Selection.Copy
'verify where is the next empty row on the destiny sheet to paste
Set eRow = Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Row
SelectedSheets.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks_:=False, Transpose:=False, Destination:=Worksheets("Test").Range(Cells(eRow, 1), Cells(eRow, 2), Cells(eRow, 3), Cells(eRow, 4))
''Copy and paste odd columns 7-19 transposing
SelectedSheets.Range(ActiveSheet.Cells(nRow, 7), SelectedSheets.Cells(nRow, 9), SelectedSheets.Cells(nRow, 11), SelectedSheets.Cells(nRow, 13), SelectedSheets.Cells(nRow, 15), SelectedSheets.Cells(nRow, 17), SelectedSheets.Cells(nRow, 19)).Select
Application.CutCopyMode = False
Selection.Copy
'verify where is the next empty row on the destiny sheet to paste
Set eRow2 = Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Row
SelectedSheets.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks_:=False, Transpose:=True, Destination:=Worksheets("Test").Range(Cells(eRow2, 7), Cells(eRow2, 9), Cells(eRow2, 11), Cells(eRow2, 13), Cells(eRow2, 15), Cells(eRow2, 17), Cells(eRow2, 19))
''Copy and paste even columns 6-20 transposing
SelectedSheets.Range(ActiveSheet.Cells(nRow, 6), SelectedSheets.Cells(nRow, 8), SelectedSheets.Cells(nRow, 10), SelectedSheets.Cells(nRow, 12), SelectedSheets.Cells(nRow, 14), SelectedSheets.Cells(nRow, 16), SelectedSheets.Cells(nRow, 18), SelectedSheets.Cells(nRow, 20)).Select
Application.CutCopyMode = False
Selection.Copy
'verify where is the next empty row on the destiny sheet to paste
Set eRow3 = Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Row
SelectedSheets.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks_:=False, Transpose:=True, Destination:=Worksheets("Test").Range(Cells(eRow3, 6), Cells(eRow3, 8), Cells(eRow3, 10), Cells(eRow3, 12), Cells(eRow3, 14), Cells(eRow3, 16), Cells(eRow3, 18), Cells(eRow3, 20))
End If
Next
End Sub
设计表:
public function up()
{
Schema::create('keyneeds', function(Blueprint $table)
{
$table->integer('id', true);
$table->integer('segment_id')->index('FK_KN_SEGMENT');
$table->integer('design_id')->index('FK_KEYNEEDS_DESIGN');
$table->integer('admin_id')->index('FK_KN_ADMIN');
$table->string('kntextcolor', 191)->nullable();
$table->string('kntextcolorhover', 191)->nullable();
$table->string('knbgcolor', 191)->nullable();
$table->string('knbgcolorhover', 191)->nullable();
$table->string('knhvize', 191)->nullable();
$table->timestamps();
$table->softDeletes();
$table->engine = 'InnoDB';
});
}
我还添加了外键约束
public function up()
{
Schema::create('designs', function(Blueprint $table)
{
$table->integer('id', true);
$table->string('design', 191)->nullable();
});
}
我尝试迁移数据库时遇到此SQL错误:
public function up()
{
Schema::table('keyneeds', function(Blueprint $table)
{
$table->foreign('design_id', 'FK_KEYNEEDS_DESIGN')->references('id')->on('designs')->onUpdate('RESTRICT')->onDelete('RESTRICT');
$table->foreign('admin_id', 'FK_KN_ADMIN')->references('id')->on('admins')->onUpdate('RESTRICT')->onDelete('RESTRICT');
$table->foreign('segment_id', 'FK_KN_SEGMENT')->references('id')->on('segments')->onUpdate('RESTRICT')->onDelete('RESTRICT');
});
}
在更新RESTRICT上删除RESTRICT时 Can not add external index constraints (SQL: alter table `keyneeds` add constraint` FK_KEYNEEDS_DESIGN` foreign key (`design_id`) references`
id`)
答案 0 :(得分:0)
Jonas Staudenmeir给出了答案:
selenium