我似乎无法弄清楚为什么我在此迁移文件中收到此错误?
错误
[37; 41m [Symfony \ Component \ Debug \ Exception \ FatalThrowableError]←[39; 49m ←[37; 41m在null上调用成员函数nullable()←[39; 49m
文件上的日期是在Customers表中创建外来ID之后。这是laravel 5.3。我该如何解决这个错误?
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('customer_id')->unsigned();
$table->timestamps('date_from')->nullable();
$table->timestamps('date_to')->nullable();
$table->date('invoice_date')->nullable();
$table->date('due_at')->nullable();
$table->integer('total_charge')->nullable();
$table->integer('rate')->nullable();
$table->integer('total_hours')->nullable();
$table->string('status')->nullable();
$table->string('description', 255)->nullable();
$table->string('notes', 255)->nullable();
$table->string('invoice_ref')->nullable();
$table->foreign('customer_id')
->references('id')->on('customers')
->onDelete('cascade');
});
}
答案 0 :(得分:5)
在这两行中使用os.listdir('/Users/liuchong/Desktop/LFW/lfw')
方法......
def copyFile(sourceDir,targetDir):
for files in os.listdir(sourceDir):
sourceFile=os.path.join(sourceDir,files)
if os.path.isfile(sourceFile) and sourceFile.find('.jpg')>0:
shutil.copy(sourceFile,targetDir)
for i in os.listdir('/Users/liuchong/Desktop/LFW/lfw'):
if os.path.isdir(i):
i = os.path.join( '/Users/liuchong/Desktop/LFW/lfw', i)
copyFile(i,'/Users/liuchong/Desktop/LFW/lfw')
timestamp
不接受任何参数并创建两个列:$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
和timestamps()
见Here
答案 1 :(得分:0)
从代码中删除这两行
$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
仅包含此行以进行timpstamping:
$table->timestamps();