A federal judge Friday blocked new regulations that would have let the Trump administration indefinitely detain migrant children and families through the length of their immigration proceedings.

U.S. District Court Judge Dolly Gee of the Central District of California issued a permanent injunction against the Trump administration’s rule, which would have placed no limit on the detention of children and changed the licensing authority for facilities housing them.

Gee found the regulations violated the terms of a 1997 settlement known as the Flores agreement that sets standards for the treatment of migrant children, including that they must be released from non-licensed facilities within 20 days.

“The blessing or the curse — depending on one’s vantage point — of a binding contract is its certitude,” Gee wrote in her order. “The Flores Agreement is a binding contract and a consent decree.”

“Defendants cannot simply ignore the dictates of the consent decree merely because they no longer agree with its approach as a matter of policy,” she wrote.

The judge added that to seek relief from such a decree, the government would have to demonstrate that a change in law or facts rendered their compliance illegal or impossible, or through a change in law from Congress.

“Having failed to obtain such relief, Defendants cannot simply impose their will by promulgating regulations that abrogate the consent decree’s most basic tenets,” she wrote. “That violates the rule of law. And that this Court cannot permit.”

The government had argued the proposed rules were intended to supersede the Flores agreement and sought to terminate the agreement.

“It’s an enormous victory for migrant children in this country,” said Holly Cooper, an attorney for the migrant children in the case. “The practical impact of her decision will be that children cannot be indefinitely detained by the federal government and states can continue to make sure the facilities in which children are detained meet basic child welfare standards.”

A Department of Justice spokesman said officials were disappointed with the ruling, calling the Flores agreement “outdated” and claiming the government had issued a rule that would protect vulnerable children and maintain family unity.

The spokesman did not mention an appeal, but the government has the option with the 9th Circuit Court of Appeals.

In a statement, the White House called the Flores agreement a “loophole” and decried “activist judges.” Gee called the Flores agreement a binding contract and consent decree.

“For two and a half years, this Administration has worked to restore faithful enforcement of the laws enacted by Congress, while activist judges have imposed their own vision in the place of those duly enacted laws,” the statement by the White House press secretary said.

In August, theadministration announced a rule with the intent of holding migrant families in detention for the duration of their immigration proceedings, with no limit on the time they can be detained.

The rule also addressed the agreement's facility requirements.

The Flores agreement said all facilities holding children for longer than 20 days must be licensed by states, but no state had licensed a family center for immigrant families.

The workaround the administration was proposing was to declare that Immigration and Customs Enforcement detention centers for families are compliant with the agreement because they are licensed by ICE, not a state.

Following the announcement of the rule, a series of state attorneys general filed a lawsuit challenging the regulations.

The Trump administration has sought to end the agreement in his attempt to deter migrant families at the southern border.