New issue. Jump to bottom. Copy link. Hi all, I recently ran into an issue when squashing migrations. I managed to find a minimal reproducible example and uploaded it here The steps I took to create this example: Create new django project and new app Create ModelA and ModelB, where ModelB has a nullable ForeignKey relation to ModelA, generate migrations Create a data migration where you create some objects of ModelA and perform some filter..
Generate migrations, selecting option 2 don't specify a default when prompted by Django. Squash these migrations The result in the database is: There are two indexes here, where I would expect only 1. Best, Florian The text was updated successfully, but these errors were encountered:. Thanks for looking into it! Fix alterfield, indexes issue …. Issue Ok, I'll take a look. IntegerField class Model2 models.
Sure, I'll try to boil my project down to a reproducible example. Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Already on GitHub? Sign in to your account. This happens in Rails 6. The text was updated successfully, but these errors were encountered:. I hope this is not me being too sleepy this morning Sorry, something went wrong. The null: false was added in The generator will still respect the Rails.
Thank so much you for pointing out the origin, the rationale and the discussion. It is very helpful. In most cases, most associations, I do want the association required by default, so I follow the usual convention.
And in my use case, I did edit the migration. So if I do Table. If you have a table column that contains NULL values, but you set a default, then that default will be returned. This is the enlightening, valuable info: "Not having NULL values might be important for indexing purposes or if you need to provide direct database access to a third party. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science.
This migration looks like exactly what we want, but when we run mix ecto. The issue is that the Ecto migrator is queueing up everything in our migration to be executed against the database.
Placing flush after the first portion of the migration will force everything queued up so far to be executed against the database. This clears the way for the rest of our migration to work. This requires some of the same tricks as the up migration because we want to be able to put the data back in place as best as we can in the event of a rollback.
In this post, we've explored a range of simple to complex Ecto migrations involving both schema changes and data transformation. We looked at how you can create new tables as well as alter existing ones. We even explored in detail how you would go about massaging and migrating data in the event that you need to replace one column with another. Ecto is an abstraction on top of SQL and we may need to drop down to raw SQL migrations in some cases, but from what we've seen Ecto can get us pretty far.
Photo credit for cover image: Paul Morris, unsplash. The following migration assumes an empty database, as if we are in the midst of creating an initial MVP of our application.
If the database already contained posts, then adding a non-nullable column would cause an error due to a violation of the not null constraint.
As we did above, the :update keyword can be used within our Query struct to specify how to update the relevant records. Stay ahead of the curve. Receive valuable blog posts, resources and event notices right to your inbox. Was this post helpful? Share it with others. Tweet Share Post.
0コメント